Skip to content

Commit 3303b22

Browse files
authored
Merge pull request #13 from byjg/fix-depecrations-php81
Fix deprecation warning for PHP 8.1.7
2 parents dfe3a08 + d9dcf0f commit 3303b22

24 files changed

+539
-196
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- uses: actions/checkout@v2
3030
- run: composer install
3131
- run: ./vendor/bin/phpunit
32+
- run: ./vendor/bin/psalm
3233

3334
Documentation:
3435
runs-on: 'ubuntu-latest'

.gitpod.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tasks:
2+
- init: |
3+
echo "No special initialization"
4+
command: |
5+
composer install
6+
7+
image:
8+
file: .gitpod/Dockerfile
9+
10+
vscode:
11+
extensions:
12+
- ikappas.composer
13+
- hbenl.test-adapter-converter
14+
- hbenl.vscode-test-explorer
15+
- felixfbecker.php-debug
16+
- neilbrayfield.php-docblocker
17+
- bmewburn.vscode-intelephense-client
18+
- getpsalm.psalm-vscode-plugin
19+
- SonarSource.sonarlint-vscode
20+
- recca0120.vscode-phpunit

.gitpod/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# You can find the new timestamped tags here: https://hub.docker.com/r/gitpod/workspace-full/tags
2+
FROM gitpod/workspace-full:latest
3+
4+
RUN sudo install-packages php-xdebug

.vscode/launch.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug current Script in Console",
9+
"type": "php",
10+
"request": "launch",
11+
"program": "${file}",
12+
"cwd": "${fileDirname}",
13+
"port": 0,
14+
"runtimeArgs": [
15+
"-dxdebug.start_with_request=yes"
16+
],
17+
"env": {
18+
"XDEBUG_MODE": "debug,develop",
19+
"XDEBUG_CONFIG": "client_port=${port}"
20+
}
21+
},
22+
{
23+
"name": "PHPUnit Debug",
24+
"type": "php",
25+
"request": "launch",
26+
"program": "${workspaceFolder}/vendor/bin/phpunit",
27+
"cwd": "${workspaceFolder}",
28+
"port": 0,
29+
"runtimeArgs": [
30+
"-dxdebug.start_with_request=yes"
31+
],
32+
"env": {
33+
"XDEBUG_MODE": "debug,develop",
34+
"XDEBUG_CONFIG": "client_port=${port}"
35+
}
36+
}
37+
]
38+
}

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"minimum-stability": "dev",
1111
"require": {
1212
"php": ">=5.6.0",
13-
"byjg/xmlutil": "1.0.*",
14-
"byjg/serializer": "1.0.*"
13+
"byjg/xmlutil": "4.9.*",
14+
"byjg/serializer": "4.9.*"
1515
},
1616
"suggest": {
1717
"ext-dom": "*"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
20+
"phpunit/phpunit": "5.7.*|7.4.*|^9.5",
21+
"vimeo/psalm": "^4.24"
2122
},
2223
"license": "MIT"
2324
}

phpunit.xml.dist

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and open the template in the editor.
77

88
<!-- see http://www.phpunit.de/wiki/Documentation -->
99
<phpunit bootstrap="./vendor/autoload.php"
10-
colors="false"
10+
colors="true"
11+
testdox="true"
1112
convertErrorsToExceptions="true"
1213
convertNoticesToExceptions="true"
1314
convertWarningsToExceptions="true"
15+
convertDeprecationsToExceptions="true"
1416
stopOnFailure="false">
1517

1618
<php>
@@ -24,11 +26,11 @@ and open the template in the editor.
2426
<directory>./src</directory>
2527
</whitelist>
2628
</filter>
27-
29+
2830
<testsuites>
2931
<testsuite name="Test Suite">
3032
<directory>./tests</directory>
3133
</testsuite>
3234
</testsuites>
33-
35+
3436
</phpunit>

psalm.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/AnyDataset.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class AnyDataset
5858

5959
/**
6060
* Path to anydataset file
61-
* @var string
61+
* @var string|null
6262
*/
6363
private $filename;
6464

6565
/**
66-
* @param string $filename
66+
* @param null|string $filename
6767
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
6868
* @throws \ByJG\Util\Exception\XmlUtilException
6969
*/
@@ -80,18 +80,23 @@ public function __construct($filename = null)
8080
});
8181
}
8282

83+
/**
84+
* @return string|null
85+
*/
8386
public function getFilename()
8487
{
8588
return $this->filename;
8689
}
8790

91+
/**
92+
*
93+
* @param string|null $file
94+
* @param mixed $closure
95+
* @return void
96+
*/
8897
private function defineSavePath($file, $closure)
8998
{
9099
if (!is_null($file)) {
91-
if (!is_string($file)) {
92-
throw new InvalidArgumentException('I expected a string as a file name');
93-
}
94-
95100
$ext = pathinfo($file, PATHINFO_EXTENSION);
96101
if (empty($ext) && substr($file, 0, 6) !== "php://") {
97102
$file .= '.anydata.xml';
@@ -106,6 +111,7 @@ private function defineSavePath($file, $closure)
106111
* Private method used to read and populate anydataset class from specified file
107112
*
108113
* @param string $filepath Path and Filename to be read
114+
* @return void
109115
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
110116
* @throws \ByJG\Util\Exception\XmlUtilException
111117
*/
@@ -121,7 +127,7 @@ private function createFrom($filepath)
121127
$fields = $row->getElementsByTagName("field");
122128
foreach ($fields as $field) {
123129
$attr = $field->attributes->getNamedItem("name");
124-
if (is_null($attr)) {
130+
if (is_null($attr) || is_null($attr->nodeValue)) {
125131
throw new InvalidArgumentException('Malformed anydataset file ' . basename($filepath));
126132
}
127133

@@ -146,7 +152,8 @@ public function xml()
146152
}
147153

148154
/**
149-
* @param string $filename
155+
* @param string|null $filename
156+
* @return void
150157
* @throws DatabaseException
151158
* @throws \ByJG\Util\Exception\XmlUtilException
152159
*/
@@ -164,7 +171,7 @@ public function save($filename = null)
164171
/**
165172
* Append one row to AnyDataset.
166173
*
167-
* @param Row|array|\stdClass|object $singleRow
174+
* @param Row|array|\stdClass|object|null $singleRow
168175
* @return void
169176
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
170177
*/
@@ -191,6 +198,7 @@ public function appendRow($singleRow = [])
191198
* Enter description here...
192199
*
193200
* @param GenericIterator $iterator
201+
* @return void
194202
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
195203
*/
196204
public function import($iterator)
@@ -204,10 +212,11 @@ public function import($iterator)
204212
* Insert one row before specified position.
205213
*
206214
* @param int $rowNumber
207-
* @param mixed $row
215+
* @param Row|array|\stdClass|object $row
216+
* @return void
208217
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
209218
*/
210-
public function insertRowBefore($rowNumber, $row = null)
219+
public function insertRowBefore($rowNumber, $row)
211220
{
212221
if ($rowNumber > count($this->collection)) {
213222
$this->appendRow($row);
@@ -216,14 +225,22 @@ public function insertRowBefore($rowNumber, $row = null)
216225
if (!($row instanceof Row)) {
217226
$singleRow = new Row($row);
218227
}
228+
229+
/**
230+
* @psalm-suppress InvalidPropertyAssignmentValue
231+
*/
219232
array_splice($this->collection, $rowNumber, 0, '');
233+
/**
234+
* @psalm-suppress InvalidPropertyAssignmentValue
235+
*/
220236
$this->collection[$rowNumber] = $singleRow;
221237
}
222238
}
223239

224240
/**
225241
*
226242
* @param mixed $row
243+
* @return void
227244
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
228245
*/
229246
public function removeRow($row = null)
@@ -291,8 +308,7 @@ public function getArray($fieldName, $itf = null)
291308
{
292309
$iterator = $this->getIterator($itf);
293310
$result = array();
294-
while ($iterator->hasNext()) {
295-
$singleRow = $iterator->moveNext();
311+
foreach ($iterator as $singleRow) {
296312
$result[] = $singleRow->get($fieldName);
297313
}
298314
return $result;
@@ -310,13 +326,11 @@ public function sort($field)
310326
}
311327

312328
$this->collection = $this->quickSortExec($this->collection, $field);
313-
314-
return;
315329
}
316330

317331
/**
318332
* @param Row[] $seq
319-
* @param $field
333+
* @param string $field
320334
* @return array
321335
*/
322336
protected function quickSortExec($seq, $field)

src/AnyIterator.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,23 @@ public function __construct($list)
3232
}
3333

3434
/**
35-
* How many elements have
36-
* @return int
35+
* @inheritDoc
3736
*/
3837
public function count()
3938
{
4039
return count($this->list);
4140
}
4241

4342
/**
44-
* Ask the Iterator is exists more rows. Use before moveNext method.
45-
* @return bool True if exist more rows, otherwise false
43+
* @inheritDoc
4644
*/
4745
public function hasNext()
4846
{
4947
return ($this->curRow < $this->count());
5048
}
5149

5250
/**
53-
* Return the next row.
54-
*
55-
* @return Row|null
51+
* @inheritDoc
5652
*/
5753
public function moveNext()
5854
{
@@ -62,6 +58,9 @@ public function moveNext()
6258
return $this->list[$this->curRow++];
6359
}
6460

61+
/**
62+
* @inheritDoc
63+
*/
6564
public function key()
6665
{
6766
return $this->curRow;

src/Formatter/BaseFormatter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ abstract class BaseFormatter implements FormatterInterface
1313
*/
1414
protected $object;
1515

16+
/**
17+
* @inheritDoc
18+
*/
1619
abstract public function raw();
1720

21+
/**
22+
* @inheritDoc
23+
*/
1824
abstract public function toText();
1925

26+
/**
27+
* @inheritDoc
28+
*/
2029
public function saveToFile($filename)
2130
{
2231
if (empty($filename)) {
@@ -26,7 +35,7 @@ public function saveToFile($filename)
2635
}
2736

2837
/**
29-
* $object AnyDataset|Row
38+
* @param GenericIterator|Row $object
3039
*/
3140
public function __construct($object)
3241
{

0 commit comments

Comments
 (0)