Skip to content

Commit 7c1ae24

Browse files
authored
Strict types=1 (#12)
* strict_types=1 * PHP 8+ in Travis-CI as experimental builds * Full Qualified Usage std functions/classes/consts * Finalize classes
1 parent aac87dc commit 7c1ae24

28 files changed

+138
-77
lines changed

.phan/config.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
$default = include __DIR__ . '/../vendor/jbzoo/codestyle/src/phan/default.php';
1819

19-
return array_merge($default, [
20+
$config = array_merge($default, [
2021
'file_list' => [
2122
'src/functions.php'
2223
],
@@ -30,3 +31,7 @@
3031
'vendor/symfony/yaml',
3132
]
3233
]);
34+
35+
$config['plugins'][] = 'NotFullyQualifiedUsagePlugin';
36+
37+
return $config;

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ php:
1919
- 7.2
2020
- 7.3
2121
- 7.4
22+
- 8.0
23+
- nightly
24+
25+
jobs:
26+
fast_finish: true
27+
allow_failures:
28+
- php: 8.0
29+
- php: nightly
2230

2331
env:
2432
matrix:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JBZoo / Data
22

3-
[![Build Status](https://travis-ci.org/JBZoo/Data.svg)](https://travis-ci.org/JBZoo/Data) [![Coverage Status](https://coveralls.io/repos/JBZoo/Data/badge.svg)](https://coveralls.io/github/JBZoo/Data) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Data/coverage.svg)](https://shepherd.dev/github/JBZoo/Data)
3+
[![Build Status](https://travis-ci.org/JBZoo/Data.svg?branch=master)](https://travis-ci.org/JBZoo/Data) [![Coverage Status](https://coveralls.io/repos/JBZoo/Data/badge.svg)](https://coveralls.io/github/JBZoo/Data) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Data/coverage.svg)](https://shepherd.dev/github/JBZoo/Data) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jbzoo/data/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jbzoo/data/?branch=master) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/data/badge)](https://www.codefactor.io/repository/github/jbzoo/data/issues) [![PHP Strict Types](https://img.shields.io/badge/strict__types-%3D1-brightgreen)](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict)
44
[![Stable Version](https://poser.pugx.org/jbzoo/data/version)](https://packagist.org/packages/jbzoo/data) [![Latest Unstable Version](https://poser.pugx.org/jbzoo/data/v/unstable)](https://packagist.org/packages/jbzoo/data) [![Dependents](https://poser.pugx.org/jbzoo/data/dependents)](https://packagist.org/packages/jbzoo/data/dependents?order_by=downloads) [![GitHub Issues](https://img.shields.io/github/issues/jbzoo/data)](https://github.com/JBZoo/Data/issues) [![Total Downloads](https://poser.pugx.org/jbzoo/data/downloads)](https://packagist.org/packages/jbzoo/data/stats) [![GitHub License](https://img.shields.io/github/license/jbzoo/data)](https://github.com/JBZoo/Data/blob/master/LICENSE)
55

66

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818

1919
"require-dev" : {
20-
"jbzoo/toolbox-dev" : "^2.9.0",
20+
"jbzoo/toolbox-dev" : "^2.9.2",
2121
"jbzoo/utils" : "^4.2.3",
2222
"symfony/yaml" : "^5.2.2"
2323
},

src/Data.php

+22-23
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
namespace JBZoo\Data;
1819

1920
use ArrayObject;
2021
use JBZoo\Utils\Filter;
21-
use RecursiveArrayIterator;
22-
use RecursiveIteratorIterator;
2322

2423
use function JBZoo\Utils\bool;
2524
use function JBZoo\Utils\float;
@@ -41,11 +40,11 @@ public function __construct($data = [])
4140
{
4241
$this->setFlags(ArrayObject::ARRAY_AS_PROPS);
4342

44-
if ($data && is_string($data) && file_exists($data)) {
43+
if ($data && \is_string($data) && \file_exists($data)) {
4544
$data = self::readFile($data);
4645
}
4746

48-
if (is_string($data)) {
47+
if (\is_string($data)) {
4948
$data = $this->decode($data);
5049
}
5150

@@ -60,17 +59,17 @@ public function __construct($data = [])
6059
protected function decode(string $string)
6160
{
6261
/** @noinspection UnserializeExploitsInspection */
63-
return unserialize($string, []);
62+
return \unserialize($string, []);
6463
}
6564

6665
/**
6766
* Utility Method to serialize the given data
6867
* @param mixed $data The data to serialize
6968
* @return string The serialized data
7069
*/
71-
protected function encode($data)
70+
protected function encode($data): string
7271
{
73-
return serialize($data);
72+
return \serialize($data);
7473
}
7574

7675
/**
@@ -168,18 +167,18 @@ public function find(string $key, $default = null, $filter = null, string $separ
168167
}
169168

170169
// explode search key and init search data
171-
$parts = (array)explode($separator, $key);
170+
$parts = (array)\explode($separator, $key);
172171
$data = $this;
173172

174173
foreach ($parts as $part) {
175174
// handle ArrayObject and Array
176-
if (($data instanceof ArrayObject || is_array($data)) && isset($data[$part])) {
175+
if (($data instanceof ArrayObject || \is_array($data)) && isset($data[$part])) {
177176
$data = $data[$part];
178177
continue;
179178
}
180179

181180
// handle object
182-
if (is_object($data) && isset($data->$part)) {
181+
if (\is_object($data) && isset($data->$part)) {
183182
$data = &$data->$part;
184183
continue;
185184
}
@@ -214,8 +213,8 @@ protected static function filter($value, $filter)
214213
*/
215214
public function search($needle)
216215
{
217-
$aIterator = new RecursiveArrayIterator($this->getArrayCopy());
218-
$iterator = new RecursiveIteratorIterator($aIterator);
216+
$aIterator = new \RecursiveArrayIterator($this->getArrayCopy());
217+
$iterator = new \RecursiveIteratorIterator($aIterator);
219218

220219
while ($iterator->valid()) {
221220
$iterator->current();
@@ -238,7 +237,7 @@ public function flattenRecursive(): array
238237
{
239238
$flat = [];
240239

241-
foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($this->getArrayCopy())) as $value) {
240+
foreach (new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->getArrayCopy())) as $value) {
242241
$flat[] = $value;
243242
}
244243

@@ -253,8 +252,8 @@ protected static function readFile(string $filePath)
253252
{
254253
$contents = false;
255254

256-
if ($realPath = realpath($filePath)) {
257-
$contents = file_get_contents($realPath);
255+
if ($realPath = \realpath($filePath)) {
256+
$contents = \file_get_contents($realPath);
258257
}
259258

260259
return $contents;
@@ -267,21 +266,21 @@ protected static function readFile(string $filePath)
267266
*/
268267
protected static function isMulti(array $array): bool
269268
{
270-
$arrayCount = array_filter($array, '\is_array');
271-
return count($arrayCount) > 0;
269+
$arrayCount = \array_filter($array, '\is_array');
270+
return \count($arrayCount) > 0;
272271
}
273272

274273
/**
275-
* @param mixed $index
274+
* @param int|string $key
276275
* @return mixed|null
277276
*/
278-
public function offsetGet($index)
277+
public function offsetGet($key)
279278
{
280-
if (!property_exists($this, $index)) {
279+
if (!\property_exists($this, (string)$key)) {
281280
return null;
282281
}
283282

284-
return parent::offsetGet($index);
283+
return parent::offsetGet($key);
285284
}
286285

287286
/**
@@ -296,7 +295,7 @@ public function offsetGet($index)
296295
*/
297296
public function is(string $key, $compareWith = true, bool $strictMode = false): bool
298297
{
299-
if (strpos($key, '.') === false) {
298+
if (\strpos($key, '.') === false) {
300299
$value = $this->get($key);
301300
} else {
302301
$value = $this->find($key);

src/Exception.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
namespace JBZoo\Data;
1819

1920
/**

src/Ini.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
namespace JBZoo\Data;
1819

1920
/**
2021
* Class Ini
2122
*
2223
* @package JBZoo\Data
2324
*/
24-
class Ini extends Data
25+
final class Ini extends Data
2526
{
2627
/**
2728
* Utility Method to unserialize the given data
@@ -31,14 +32,14 @@ class Ini extends Data
3132
*/
3233
protected function decode(string $string)
3334
{
34-
return parse_ini_string($string, true, INI_SCANNER_NORMAL);
35+
return \parse_ini_string($string, true, \INI_SCANNER_NORMAL);
3536
}
3637

3738
/**
3839
* @param mixed $data
3940
* @return string
4041
*/
41-
protected function encode($data)
42+
protected function encode($data): string
4243
{
4344
return $this->render($data, []);
4445
}
@@ -52,22 +53,22 @@ protected function render(array $data = [], array $parent = []): string
5253
{
5354
$result = [];
5455
foreach ($data as $dataKey => $dataValue) {
55-
if (is_array($dataValue)) {
56+
if (\is_array($dataValue)) {
5657
if (self::isMulti($dataValue)) {
57-
$sections = array_merge($parent, (array)$dataKey);
58+
$sections = \array_merge($parent, (array)$dataKey);
5859
$result[] = '';
59-
$result[] = '[' . implode('.', $sections) . ']';
60+
$result[] = '[' . \implode('.', $sections) . ']';
6061
$result[] = $this->render($dataValue, $sections);
6162
} else {
6263
foreach ($dataValue as $key => $value) {
63-
$result[] = $dataKey . '[' . $key . '] = "' . str_replace('"', '\"', $value) . '"';
64+
$result[] = $dataKey . '[' . $key . '] = "' . \str_replace('"', '\"', $value) . '"';
6465
}
6566
}
6667
} else {
67-
$result[] = $dataKey . ' = "' . str_replace('"', '\"', $dataValue) . '"';
68+
$result[] = $dataKey . ' = "' . \str_replace('"', '\"', $dataValue) . '"';
6869
}
6970
}
7071

71-
return implode(Data::LE, $result);
72+
return \implode(Data::LE, $result);
7273
}
7374
}

src/JSON.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
namespace JBZoo\Data;
1819

1920
/**
2021
* Class JSON
2122
*
2223
* @package JBZoo\Data
2324
*/
24-
class JSON extends Data
25+
final class JSON extends Data
2526
{
2627
/**
2728
* Utility Method to unserialize the given data
@@ -31,7 +32,7 @@ class JSON extends Data
3132
*/
3233
protected function decode(string $string)
3334
{
34-
return json_decode($string, true, 512, JSON_BIGINT_AS_STRING);
35+
return \json_decode($string, true, 512, \JSON_BIGINT_AS_STRING);
3536
}
3637

3738
/**
@@ -42,6 +43,6 @@ protected function decode(string $string)
4243
*/
4344
protected function encode($data): string
4445
{
45-
return (string)json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING);
46+
return (string)\json_encode($data, \JSON_PRETTY_PRINT | \JSON_BIGINT_AS_STRING);
4647
}
4748
}

src/PhpArray.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
* @license MIT
1212
* @copyright Copyright (C) JBZoo.com, All rights reserved.
1313
* @link https://github.com/JBZoo/Data
14-
* @author Denis Smetannikov <denis@jbzoo.com>
1514
*/
1615

16+
declare(strict_types=1);
17+
1718
namespace JBZoo\Data;
1819

1920
/**
2021
* Class PhpArray
2122
* @package JBZoo\Data
2223
*/
23-
class PhpArray extends Data
24+
final class PhpArray extends Data
2425
{
2526
/**
2627
* Class constructor
@@ -29,7 +30,7 @@ class PhpArray extends Data
2930
*/
3031
public function __construct($data = [])
3132
{
32-
if ($data && is_string($data) && file_exists($data)) {
33+
if ($data && \is_string($data) && \file_exists($data)) {
3334
$data = $this->decode($data);
3435
}
3536

@@ -44,7 +45,7 @@ public function __construct($data = [])
4445
*/
4546
protected function decode(string $string)
4647
{
47-
if (file_exists($string)) {
48+
if (\file_exists($string)) {
4849
return include $string;
4950
}
5051
}
@@ -55,14 +56,14 @@ protected function decode(string $string)
5556
* @param mixed $data The data to serialize
5657
* @return string The serialized data
5758
*/
58-
protected function encode($data)
59+
protected function encode($data): string
5960
{
6061
$data = [
6162
'<?php',
6263
'',
63-
'return ' . var_export($data, true) . ';',
64+
'return ' . \var_export($data, true) . ';',
6465
];
6566

66-
return implode(self::LE, $data);
67+
return \implode(self::LE, $data);
6768
}
6869
}

0 commit comments

Comments
 (0)