Skip to content

Commit b1fde0b

Browse files
authored
v0.6.5 (#6)
1 parent aa596da commit b1fde0b

7 files changed

+33
-148
lines changed

Dockerfile

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:1.10.10 as composer
1+
FROM composer:1.10.16 as composer
22

33
WORKDIR /usr/src/php-pcap-ffi
44

@@ -17,6 +17,21 @@ FROM php:7.4-cli-alpine
1717
RUN apk add bind-tools libffi libffi-dev libpcap && \
1818
docker-php-ext-install ffi sockets
1919

20+
# Build and install pcov
21+
ARG PHP_PCOV_RELEASE=3546be8
22+
RUN cd /tmp && \
23+
curl https://codeload.github.com/krakjoe/pcov/tar.gz/$PHP_PCOV_RELEASE | tar xvz && \
24+
cd /tmp/pcov-$PHP_PCOV_RELEASE && \
25+
apk --no-cache add $PHPIZE_DEPS && \
26+
phpize && \
27+
./configure && \
28+
make && \
29+
make install && \
30+
echo "extension=pcov.so" > /usr/local/etc/php/conf.d/pcov.ini
31+
# Remove build dependencies
32+
RUN apk --purge del $PHPIZE_DEPS && \
33+
rm -rf /tmp/*
34+
2035
WORKDIR /usr/src/php-pcap-ffi
2136

2237
COPY . /usr/src/php-pcap-ffi

Dockerfile.buster

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:1.10.10 as composer
1+
FROM composer:1.10.16 as composer
22

33
WORKDIR /usr/src/php-pcap-ffi
44

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
Stream driven PHP packet capture library, leveraging libpcap via FFI.
44

5-
[![Build Status](https://travis-ci.com/rtckit/php-pcap-ffi.svg?branch=master)](https://travis-ci.com/rtckit/php-pcap-ffi) ![Version](https://img.shields.io/badge/version-v0.6.4-green) ![License](https://img.shields.io/badge/license-MIT-blue)
5+
[![Build Status](https://travis-ci.com/rtckit/php-pcap-ffi.svg?branch=master)](https://travis-ci.com/rtckit/php-pcap-ffi)
6+
[![Latest Stable Version](https://poser.pugx.org/rtckit/pcap-ffi/v/stable.png)](https://packagist.org/packages/rtckit/pcap-ffi)
7+
[![Maintainability](https://api.codeclimate.com/v1/badges/e8c2dca80074553ba561/maintainability)](https://codeclimate.com/github/rtckit/php-pcap-ffi/maintainability)
8+
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
69

710
## Pcap Extension
811

@@ -23,7 +26,7 @@ The recommended way to install this library is [through Composer](https://getcom
2326
This will install the latest supported version:
2427

2528
```sh
26-
composer require rtckit/pcap-ffi:^0.6.4
29+
composer require rtckit/pcap-ffi:^0.6.5
2730
```
2831

2932
## Tests

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rtckit/pcap-ffi",
33
"description": "PHP Packet Capture via libpcap through FFI",
4-
"version": "0.6.4",
4+
"version": "0.6.5",
55
"type": "library",
66
"keywords": [
77
"packet",
@@ -26,8 +26,8 @@
2626
"ext-ffi": "*"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^9.3",
30-
"vimeo/psalm": "^3.15",
29+
"phpunit/phpunit": "^9.4",
30+
"vimeo/psalm": "^4.0",
3131
"phpstan/phpstan": "^0.12"
3232
},
3333
"autoload": {

phpstan.neon

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ parameters:
22
ignoreErrors:
33
- '#Call to an undefined method FFI::pcap_#'
44
- '#Cannot access offset 0 on FFI\\CData#'
5-
- '#\$pcap of method RTCKit\\Pcap\\Stream\\FFI\\PcapFFI::inject\(\) expects FFI\\CData, FFI\\CData\|null given.#'
6-
- '#\$pcap of method RTCKit\\Pcap\\Stream\\FFI\\PcapFFI::next_ex\(\) expects FFI\\CData, FFI\\CData\|null given.#'
7-
- '#\$pcap of method RTCKit\\Pcap\\Stream\\FFI\\PcapFFI::get_selectable_fd\(\) expects FFI\\CData, FFI\\CData\|null given.#'
85
includes:
96
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

psalm.xml

-130
Original file line numberDiff line numberDiff line change
@@ -13,136 +13,6 @@
1313
</projectFiles>
1414

1515
<issueHandlers>
16-
<LessSpecificReturnType errorLevel="info" />
17-
18-
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
19-
20-
<DeprecatedMethod errorLevel="info" />
21-
<DeprecatedProperty errorLevel="info" />
22-
<DeprecatedClass errorLevel="info" />
23-
<DeprecatedConstant errorLevel="info" />
24-
<DeprecatedFunction errorLevel="info" />
25-
<DeprecatedInterface errorLevel="info" />
26-
<DeprecatedTrait errorLevel="info" />
27-
28-
<InternalMethod errorLevel="info" />
29-
<InternalProperty errorLevel="info" />
30-
<InternalClass errorLevel="info" />
31-
32-
<MissingClosureReturnType errorLevel="info" />
33-
<MissingReturnType errorLevel="info" />
34-
<MissingPropertyType errorLevel="info" />
35-
<InvalidDocblock errorLevel="info" />
36-
<MisplacedRequiredParam errorLevel="info" />
37-
38-
<PropertyNotSetInConstructor errorLevel="info" />
39-
<MissingConstructor errorLevel="info" />
40-
<MissingClosureParamType errorLevel="info" />
41-
<MissingParamType errorLevel="info" />
42-
43-
<RedundantCondition errorLevel="info" />
44-
45-
<DocblockTypeContradiction errorLevel="info" />
46-
<RedundantConditionGivenDocblockType errorLevel="info" />
47-
48-
<UnresolvableInclude errorLevel="info" />
49-
50-
<RawObjectIteration errorLevel="info" />
51-
52-
<InvalidStringClass errorLevel="info" />
53-
54-
<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->
55-
56-
<MoreSpecificReturnType errorLevel="info" />
57-
<LessSpecificReturnStatement errorLevel="info" />
58-
<TypeCoercion errorLevel="info" />
59-
60-
<PossiblyFalseArgument errorLevel="info" />
61-
<PossiblyFalseIterator errorLevel="info" />
62-
<PossiblyFalseOperand errorLevel="info" />
63-
<PossiblyFalsePropertyAssignmentValue errorLevel="info" />
64-
<PossiblyFalseReference errorLevel="info" />
65-
<PossiblyInvalidArgument errorLevel="info" />
66-
<PossiblyInvalidArrayAccess errorLevel="info" />
67-
<PossiblyInvalidArrayAssignment errorLevel="info" />
68-
<PossiblyInvalidArrayOffset errorLevel="info" />
69-
<PossiblyInvalidCast errorLevel="info" />
70-
<PossiblyInvalidFunctionCall errorLevel="info" />
71-
<PossiblyInvalidIterator errorLevel="info" />
72-
<PossiblyInvalidMethodCall errorLevel="info" />
73-
<PossiblyInvalidOperand errorLevel="info" />
74-
<PossiblyInvalidPropertyAssignment errorLevel="info" />
75-
<PossiblyInvalidPropertyAssignmentValue errorLevel="info" />
76-
<PossiblyInvalidPropertyFetch errorLevel="info" />
77-
<PossiblyNullArgument errorLevel="info" />
78-
<PossiblyNullArrayAccess errorLevel="info" />
79-
<PossiblyNullArrayAssignment errorLevel="info" />
80-
<PossiblyNullArrayOffset errorLevel="info" />
81-
<PossiblyNullFunctionCall errorLevel="info" />
82-
<PossiblyNullIterator errorLevel="info" />
83-
<PossiblyNullOperand errorLevel="info" />
84-
<PossiblyNullPropertyAssignment errorLevel="info" />
85-
<PossiblyNullPropertyAssignmentValue errorLevel="info" />
86-
<PossiblyNullPropertyFetch errorLevel="info" />
87-
<PossiblyNullReference errorLevel="info" />
88-
<PossiblyUndefinedGlobalVariable errorLevel="info" />
89-
<PossiblyUndefinedVariable errorLevel="info" />
90-
<PossiblyUndefinedArrayOffset errorLevel="info" />
91-
<PossiblyUndefinedMethod errorLevel="info" />
92-
93-
<!-- level 5 issues - should be avoided at mosts costs... -->
94-
95-
<ForbiddenCode errorLevel="info" />
96-
<ImplicitToStringCast errorLevel="info" />
97-
<InvalidScalarArgument errorLevel="info" />
98-
<InvalidToString errorLevel="info" />
99-
<InvalidOperand errorLevel="info" />
100-
<NoInterfaceProperties errorLevel="info" />
101-
<TooManyArguments errorLevel="info" />
102-
<TypeDoesNotContainType errorLevel="info" />
103-
<TypeDoesNotContainNull errorLevel="info" />
104-
<MissingDocblockType errorLevel="info" />
105-
<ImplementedReturnTypeMismatch errorLevel="info" />
106-
<ImplementedParamTypeMismatch errorLevel="info" />
107-
108-
<!-- level 6 issues - really bad things -->
109-
110-
<InvalidNullableReturnType errorLevel="info" />
111-
<NullableReturnStatement errorLevel="info" />
112-
<InvalidFalsableReturnType errorLevel="info" />
113-
<FalsableReturnStatement errorLevel="info" />
114-
115-
<MoreSpecificImplementedParamType errorLevel="info" />
116-
<LessSpecificImplementedReturnType errorLevel="info" />
117-
118-
<InvalidReturnStatement errorLevel="info" />
119-
<InvalidReturnType errorLevel="info" />
120-
<UndefinedThisPropertyAssignment errorLevel="info" />
121-
<UndefinedInterfaceMethod errorLevel="info" />
122-
123-
<!-- level 7 issues - even worse -->
124-
125-
<UndefinedThisPropertyAssignment errorLevel="info" />
126-
<UndefinedPropertyAssignment errorLevel="info" />
127-
<UndefinedThisPropertyFetch errorLevel="info" />
128-
<UndefinedPropertyFetch errorLevel="info" />
129-
130-
<InvalidReturnStatement errorLevel="info" />
131-
<InvalidReturnType errorLevel="info" />
132-
<InvalidArgument errorLevel="info" />
133-
<InvalidPropertyAssignmentValue errorLevel="info" />
134-
<InvalidArrayOffset errorLevel="info" />
135-
<InvalidArrayAssignment errorLevel="info" />
136-
<InvalidArrayAccess errorLevel="info" />
137-
<InvalidClone errorLevel="info" />
138-
139-
<!-- level 8 issues - some fatal errors in PHP -->
140-
141-
<ReservedWord errorLevel="info" />
142-
<MethodSignatureMismatch errorLevel="info" />
143-
<OverriddenMethodAccess errorLevel="info" />
144-
<InaccessibleProperty errorLevel="info" />
145-
14616
<UndefinedMethod>
14717
<errorLevel type="suppress">
14818
<referencedMethod name="FFI::pcap_lib_version" />

src/StreamWrapper.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class StreamWrapper
2626
* - https://bugs.php.net/bug.php?id=71518
2727
*
2828
* @var ?resource
29+
* @psalm-var resource|closed-resource|null
2930
*/
3031
private $fp = null;
3132

@@ -68,7 +69,7 @@ private function closeSession(): void
6869
$this->pcap = null;
6970
}
7071

71-
if (!is_null($this->fp)) {
72+
if (is_resource($this->fp)) {
7273
fclose($this->fp);
7374
$this->fp = null;
7475
}
@@ -146,14 +147,12 @@ private function activateSession(): ?CData
146147
$this->fail("Cannot set filter option on device {$this->dev}: " . $this->pcapFFI->getLastError());
147148
}
148149

149-
$this->pcap = $pcap;
150-
151-
return $this->pcap;
150+
return $pcap;
152151
}
153152

154153
public function stream_write(string $data): int
155154
{
156-
if (is_null($this->pcap) && is_null($this->activateSession())) {
155+
if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
157156
return -1;
158157
}
159158

@@ -168,7 +167,7 @@ public function stream_write(string $data): int
168167

169168
public function stream_read(int $count): string
170169
{
171-
if (is_null($this->pcap) && is_null($this->activateSession())) {
170+
if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
172171
return '';
173172
}
174173

@@ -273,14 +272,14 @@ public function stream_close(): void
273272
*/
274273
public function stream_cast(int $cast_as)
275274
{
276-
if (is_null($this->pcap) && is_null($this->activateSession())) {
275+
if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
277276
return false;
278277
}
279278

280279
switch ($cast_as) {
281280
case STREAM_CAST_FOR_SELECT:
282281
case STREAM_CAST_AS_STREAM:
283-
if (!is_null($this->fp)) {
282+
if (is_resource($this->fp)) {
284283
return $this->fp;
285284
}
286285

@@ -305,6 +304,7 @@ public function stream_cast(int $cast_as)
305304
stream_set_read_buffer($this->fp, 0);
306305
}
307306

307+
/** @var resource */
308308
return $this->fp;
309309
}
310310

0 commit comments

Comments
 (0)