From 3d84f82cc1d847f072d4c0e0bee6f4da16a066e8 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:16:49 -0400 Subject: [PATCH 01/15] Exclude unnecessary files from release archive exports --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2fb94da --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore From a48109d7945c2d803c8c489f6d0b3e8366a7915f Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 10:59:33 -0400 Subject: [PATCH 02/15] Bump minimum PHP version to 7.1; test up to PHP 7.4 This will allow us to use class constant visibility and nullable types --- .travis.yml | 3 ++- README.md | 2 +- composer.json | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7dc0a79..d35938c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: php php: - - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 before_script: - wget -nc http://getcomposer.org/composer.phar diff --git a/README.md b/README.md index ebcbbbb..9a73d6f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Given a deep data structure, access data by dot notation. Requirements ------------ - * PHP (7.0+) + * PHP (7.1+) > For PHP (5.3+) please refer to version `1.0`. diff --git a/composer.json b/composer.json index 9911c53..378eaf2 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { "phpunit/phpunit": "^6.0" From d37c5d1382561fc68b283daa3e9586a9ab9264b9 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:03:49 -0400 Subject: [PATCH 03/15] Switch from Travis CI to Github Actions Github Actions is significantly faster and provides nicer feedback about test failures. --- .gitattributes | 2 +- .github/workflows/tests.yml | 29 +++++++++++++++++++++++++++++ .travis.yml | 13 ------------- 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 2fb94da..3238799 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,7 @@ # Ignore all test and documentation with "export-ignore". /.gitattributes export-ignore +/.github export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore /tests export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3c3891b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,29 @@ +name: Tests + +on: + push: ~ + pull_request: ~ + +jobs: + phpunit: + name: PHPUnit on ${{ matrix.php }} ${{ matrix.composer-flags }} + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.1', '7.2', '7.3', '7.4'] + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: curl + coverage: pcov + tools: composer:v2 + + - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - run: composer update --no-progress + + - run: vendor/bin/phpunit --coverage-text diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d35938c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -before_script: - - wget -nc http://getcomposer.org/composer.phar - - php composer.phar install - -script: ./vendor/bin/phpunit --coverage-text From d525666ed5564b15a98607b618ed6f7fea7894f8 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:09:01 -0400 Subject: [PATCH 04/15] Test using newer versions of PHPUnit --- .gitignore | 2 ++ composer.json | 2 +- phpunit.xml.dist | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 987e2a2..f973ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.phpunit.result.cache composer.lock +phpunit.xml vendor diff --git a/composer.json b/composer.json index 378eaf2..156a314 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ce9bb37..b2c4433 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,14 @@ - + ./tests From bac904fda42a2830c6e3275be1a868cfc65d2659 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:11:32 -0400 Subject: [PATCH 05/15] Test on PHP 8 --- .github/workflows/tests.yml | 16 +++++++++++++++- composer.json | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3c3891b..50728f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,12 @@ jobs: strategy: matrix: php: ['7.1', '7.2', '7.3', '7.4'] + coverage: [true] + composer-flags: [''] + include: + - php: '8.0' + coverage: false + composer-flags: '--ignore-platform-req=php' steps: - uses: actions/checkout@v2 @@ -24,6 +30,14 @@ jobs: - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - run: composer update --no-progress + - name: "Use PHPUnit 9.3+ on PHP 8" + run: composer require --no-update --dev phpunit/phpunit:^9.3 + if: "matrix.php == '8.0'" + + - run: composer update --no-progress ${{ matrix.composer-flags }} + + - run: vendor/bin/phpunit --no-coverage + if: ${{ !matrix.coverage }} - run: vendor/bin/phpunit --coverage-text + if: ${{ matrix.coverage }} diff --git a/composer.json b/composer.json index 156a314..07bbb91 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3" From 9961e9a040774a489383bfa67c7a3d939081e910 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:14:02 -0400 Subject: [PATCH 06/15] Add phpstan and psalm for static analysis --- .gitattributes | 2 ++ .github/workflows/tests.yml | 36 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ composer.json | 4 +++- phpstan.neon.dist | 4 ++++ psalm.xml.dist | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon.dist create mode 100644 psalm.xml.dist diff --git a/.gitattributes b/.gitattributes index 3238799..218cd6e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,5 +5,7 @@ /.gitattributes export-ignore /.github export-ignore /.gitignore export-ignore +/phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore +/psalm.xml.dist export-ignore /tests export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 50728f7..463e1ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,3 +41,39 @@ jobs: - run: vendor/bin/phpunit --coverage-text if: ${{ matrix.coverage }} + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + extensions: curl + coverage: none + tools: composer:v2 + + - run: composer update --no-progress + + - run: vendor/bin/phpstan analyse --no-progress + + psalm: + name: Psalm + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + extensions: curl + coverage: none + tools: composer:v2 + + - run: composer update --no-progress + + - run: vendor/bin/psalm --no-progress --output-format=github diff --git a/.gitignore b/.gitignore index f973ee0..b31c0cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .phpunit.result.cache composer.lock +phpstan.neon phpunit.xml +psalm.xml vendor diff --git a/composer.json b/composer.json index 07bbb91..0d56a7f 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,9 @@ "php": "^7.1 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3" + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", + "vimeo/psalm": "^3.14" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..a1c637a --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: max + paths: + - src diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..729e9a9 --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,16 @@ + + + + + + + + + From bbbc4c3861a6e1d1896c943e8a9a1e8f240aba56 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:30:04 -0400 Subject: [PATCH 07/15] Remove redundant array check found by Psalm --- src/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util.php b/src/Util.php index 546da22..3f72c7a 100644 --- a/src/Util.php +++ b/src/Util.php @@ -25,7 +25,7 @@ class Util */ public static function isAssoc(array $arr) { - return (is_array($arr) && (!count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr))); + return !count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr); } /** From 8d9590873b46fe70ee7e0becc8c0aa94fb38382f Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:46:20 -0400 Subject: [PATCH 08/15] Clean up type definition issues found by phpstan --- src/Data.php | 26 +++++++++++++------------- src/DataInterface.php | 24 ++++++++++++------------ src/Util.php | 12 +++++++----- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Data.php b/src/Data.php index 1cec9a6..695aefc 100644 --- a/src/Data.php +++ b/src/Data.php @@ -18,24 +18,24 @@ class Data implements DataInterface /** * Internal representation of data data * - * @var array + * @var array */ protected $data; /** * Constructor * - * @param array|null $data + * @param array $data */ - public function __construct(array $data = null) + public function __construct(array $data = []) { - $this->data = $data ?: []; + $this->data = $data; } /** * {@inheritdoc} */ - public function append($key, $value = null) + public function append(string $key, $value = null): void { if (0 == strlen($key)) { throw new RuntimeException("Key cannot be an empty string"); @@ -81,7 +81,7 @@ public function append($key, $value = null) /** * {@inheritdoc} */ - public function set($key, $value = null) + public function set(string $key, $value = null): void { if (0 == strlen($key)) { throw new RuntimeException("Key cannot be an empty string"); @@ -113,7 +113,7 @@ public function set($key, $value = null) /** * {@inheritdoc} */ - public function remove($key) + public function remove(string $key): void { if (0 == strlen($key)) { throw new RuntimeException("Key cannot be an empty string"); @@ -142,7 +142,7 @@ public function remove($key) /** * {@inheritdoc} */ - public function get($key, $default = null) + public function get(string $key, $default = null) { $currentValue = $this->data; $keyPath = explode('.', $key); @@ -164,7 +164,7 @@ public function get($key, $default = null) /** * {@inheritdoc} */ - public function has($key) + public function has(string $key): bool { $currentValue = &$this->data; $keyPath = explode('.', $key); @@ -186,7 +186,7 @@ public function has($key) /** * {@inheritdoc} */ - public function getData($key) + public function getData(string $key): DataInterface { $value = $this->get($key); if (is_array($value) && Util::isAssoc($value)) { @@ -199,7 +199,7 @@ public function getData($key) /** * {@inheritdoc} */ - public function import(array $data, $clobber = true) + public function import(array $data, bool $clobber = true): void { $this->data = Util::mergeAssocArray($this->data, $data, $clobber); } @@ -207,7 +207,7 @@ public function import(array $data, $clobber = true) /** * {@inheritdoc} */ - public function importData(DataInterface $data, $clobber = true) + public function importData(DataInterface $data, bool $clobber = true): void { $this->import($data->export(), $clobber); } @@ -215,7 +215,7 @@ public function importData(DataInterface $data, $clobber = true) /** * {@inheritdoc} */ - public function export() + public function export(): array { return $this->data; } diff --git a/src/DataInterface.php b/src/DataInterface.php index 3498f26..d5ddf04 100644 --- a/src/DataInterface.php +++ b/src/DataInterface.php @@ -19,7 +19,7 @@ interface DataInterface * @param string $key * @param mixed $value */ - public function append($key, $value = null); + public function append(string $key, $value = null): void; /** * Set a value for a key @@ -27,14 +27,14 @@ public function append($key, $value = null); * @param string $key * @param mixed $value */ - public function set($key, $value = null); + public function set(string $key, $value = null): void; /** * Remove a key * * @param string $key */ - public function remove($key); + public function remove(string $key): void; /** * Get the raw value for a key @@ -44,7 +44,7 @@ public function remove($key); * * @return mixed */ - public function get($key, $default = null); + public function get(string $key, $default = null); /** * Check if the key exists @@ -53,7 +53,7 @@ public function get($key, $default = null); * * @return bool */ - public function has($key); + public function has(string $key): bool; /** * Get a data instance for a key @@ -62,15 +62,15 @@ public function has($key); * * @return DataInterface */ - public function getData($key); + public function getData(string $key): DataInterface; /** * Import data into existing data * - * @param array $data - * @param bool $clobber + * @param array $data + * @param bool $clobber */ - public function import(array $data, $clobber = true); + public function import(array $data, bool $clobber = true): void; /** * Import data from an external data into existing data @@ -78,12 +78,12 @@ public function import(array $data, $clobber = true); * @param DataInterface $data * @param bool $clobber */ - public function importData(DataInterface $data, $clobber = true); + public function importData(DataInterface $data, bool $clobber = true): void; /** * Export data as raw data * - * @return array + * @return array */ - public function export(); + public function export(): array; } diff --git a/src/Util.php b/src/Util.php index 3f72c7a..1310163 100644 --- a/src/Util.php +++ b/src/Util.php @@ -19,11 +19,11 @@ class Util * Note that this function will return true if an array is empty. Meaning * empty arrays will be treated as if they are associative arrays. * - * @param array $arr + * @param array $arr * - * @return boolean + * @return bool */ - public static function isAssoc(array $arr) + public static function isAssoc(array $arr): bool { return !count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr); } @@ -31,9 +31,11 @@ public static function isAssoc(array $arr) /** * Merge contents from one associtative array to another * - * @param array $to - * @param array $from + * @param mixed $to + * @param mixed $from * @param bool $clobber + * + * @return mixed */ public static function mergeAssocArray($to, $from, $clobber = true) { From d52384261b723875f40e684528a1e46ec3161e1b Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 12:05:14 -0400 Subject: [PATCH 09/15] Add psalm purity markers --- src/Data.php | 8 ++++++++ src/DataInterface.php | 8 ++++++++ src/Util.php | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/Data.php b/src/Data.php index 695aefc..c36c904 100644 --- a/src/Data.php +++ b/src/Data.php @@ -141,6 +141,8 @@ public function remove(string $key): void /** * {@inheritdoc} + * + * @psalm-mutation-free */ public function get(string $key, $default = null) { @@ -163,6 +165,8 @@ public function get(string $key, $default = null) /** * {@inheritdoc} + * + * @psalm-mutation-free */ public function has(string $key): bool { @@ -185,6 +189,8 @@ public function has(string $key): bool /** * {@inheritdoc} + * + * @psalm-mutation-free */ public function getData(string $key): DataInterface { @@ -214,6 +220,8 @@ public function importData(DataInterface $data, bool $clobber = true): void /** * {@inheritdoc} + * + * @psalm-mutation-free */ public function export(): array { diff --git a/src/DataInterface.php b/src/DataInterface.php index d5ddf04..fa20196 100644 --- a/src/DataInterface.php +++ b/src/DataInterface.php @@ -43,6 +43,8 @@ public function remove(string $key): void; * @param mixed $default * * @return mixed + * + * @psalm-mutation-free */ public function get(string $key, $default = null); @@ -52,6 +54,8 @@ public function get(string $key, $default = null); * @param string $key * * @return bool + * + * @psalm-mutation-free */ public function has(string $key): bool; @@ -61,6 +65,8 @@ public function has(string $key): bool; * @param string $key * * @return DataInterface + * + * @psalm-mutation-free */ public function getData(string $key): DataInterface; @@ -84,6 +90,8 @@ public function importData(DataInterface $data, bool $clobber = true): void; * Export data as raw data * * @return array + * + * @psalm-mutation-free */ public function export(): array; } diff --git a/src/Util.php b/src/Util.php index 1310163..6419c41 100644 --- a/src/Util.php +++ b/src/Util.php @@ -22,6 +22,8 @@ class Util * @param array $arr * * @return bool + * + * @psalm-pure */ public static function isAssoc(array $arr): bool { @@ -36,6 +38,8 @@ public static function isAssoc(array $arr): bool * @param bool $clobber * * @return mixed + * + * @psalm-pure */ public static function mergeAssocArray($to, $from, $clobber = true) { From d55cd4959c45a15c21bfad9fa2030269dc0ca8a7 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:54:44 -0400 Subject: [PATCH 10/15] Check code style against PSR-12 --- .gitattributes | 1 + .github/workflows/tests.yml | 18 ++++++++++++++++++ .gitignore | 2 ++ composer.json | 1 + phpcs.xml.dist | 17 +++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/.gitattributes b/.gitattributes index 218cd6e..16efe8b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,7 @@ /.gitattributes export-ignore /.github export-ignore /.gitignore export-ignore +/phpcs.xml.dist export-ignore /phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore /psalm.xml.dist export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 463e1ea..bc60942 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,24 @@ on: pull_request: ~ jobs: + phpcs: + name: PHPCS + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + extensions: curl, mbstring + coverage: none + tools: composer:v2, cs2pr + + - run: composer update --no-progress + + - run: vendor/bin/phpcs -q --report=checkstyle | cs2pr + phpunit: name: PHPUnit on ${{ matrix.php }} ${{ matrix.composer-flags }} runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index b31c0cf..a0a4f20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +.phpcs-cache .phpunit.result.cache composer.lock +phpcs.xml phpstan.neon phpunit.xml psalm.xml diff --git a/composer.json b/composer.json index 0d56a7f..8a12e42 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "require-dev": { "phpstan/phpstan": "^0.12.42", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", + "squizlabs/php_codesniffer": "^3.5", "vimeo/psalm": "^3.14" }, "autoload": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..d67debb --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,17 @@ + + + + + + + + + + + + + src + tests + + + From 392d36e122ac34147c8c14742b00f415919e21d6 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:55:12 -0400 Subject: [PATCH 11/15] Update code to match PSR-12 code style --- src/Data.php | 14 +++++++------- src/Util.php | 4 ++-- tests/DataTest.php | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Data.php b/src/Data.php index c36c904..53ea64a 100644 --- a/src/Data.php +++ b/src/Data.php @@ -59,9 +59,9 @@ public function append(string $key, $value = null): void } $endKey = array_pop($keyPath); - for ( $i = 0; $i < count($keyPath); $i++ ) { + for ($i = 0; $i < count($keyPath); $i++) { $currentKey =& $keyPath[$i]; - if ( ! isset($currentValue[$currentKey]) ) { + if (! isset($currentValue[$currentKey])) { $currentValue[$currentKey] = []; } $currentValue =& $currentValue[$currentKey]; @@ -97,7 +97,7 @@ public function set(string $key, $value = null): void } $endKey = array_pop($keyPath); - for ( $i = 0; $i < count($keyPath); $i++ ) { + for ($i = 0; $i < count($keyPath); $i++) { $currentKey =& $keyPath[$i]; if (!isset($currentValue[$currentKey])) { $currentValue[$currentKey] = []; @@ -129,7 +129,7 @@ public function remove(string $key): void } $endKey = array_pop($keyPath); - for ( $i = 0; $i < count($keyPath); $i++ ) { + for ($i = 0; $i < count($keyPath); $i++) { $currentKey =& $keyPath[$i]; if (!isset($currentValue[$currentKey])) { return; @@ -149,9 +149,9 @@ public function get(string $key, $default = null) $currentValue = $this->data; $keyPath = explode('.', $key); - for ( $i = 0; $i < count($keyPath); $i++ ) { + for ($i = 0; $i < count($keyPath); $i++) { $currentKey = $keyPath[$i]; - if (!isset($currentValue[$currentKey]) ) { + if (!isset($currentValue[$currentKey])) { return $default; } if (!is_array($currentValue)) { @@ -173,7 +173,7 @@ public function has(string $key): bool $currentValue = &$this->data; $keyPath = explode('.', $key); - for ( $i = 0; $i < count($keyPath); $i++ ) { + for ($i = 0; $i < count($keyPath); $i++) { $currentKey = $keyPath[$i]; if ( !is_array($currentValue) || diff --git a/src/Util.php b/src/Util.php index 6419c41..a9cc2cc 100644 --- a/src/Util.php +++ b/src/Util.php @@ -27,7 +27,7 @@ class Util */ public static function isAssoc(array $arr): bool { - return !count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr); + return !count($arr) || count(array_filter(array_keys($arr), 'is_string')) == count($arr); } /** @@ -43,7 +43,7 @@ public static function isAssoc(array $arr): bool */ public static function mergeAssocArray($to, $from, $clobber = true) { - if ( is_array($from) ) { + if (is_array($from)) { foreach ($from as $k => $v) { if (!isset($to[$k])) { $to[$k] = $v; diff --git a/tests/DataTest.php b/tests/DataTest.php index d80e052..b3b1ad1 100644 --- a/tests/DataTest.php +++ b/tests/DataTest.php @@ -88,7 +88,7 @@ public function testAppend() public function testSet() { - $data = new Data; + $data = new Data(); $this->assertNull($data->get('a')); $this->assertNull($data->get('b.c')); @@ -111,7 +111,7 @@ public function testSet() public function testSetClobberStringInPath() { - $data = new Data; + $data = new Data(); $data->set('a.b.c', 'Should not be able to write to a.b.c.d.e'); From 6f7a42d35a5e5c3a7895a5135700c0de0e78d618 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:56:39 -0400 Subject: [PATCH 12/15] Add .editorconfig file to pre-configure contributor IDEs --- .editorconfig | 11 +++++++++++ .gitattributes | 1 + 2 files changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2454616 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +; top-most EditorConfig file +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes index 16efe8b..7a6ef08 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". +/.editorconfig export-ignore /.gitattributes export-ignore /.github export-ignore /.gitignore export-ignore From 97e1c611a3fc905d4c39b21277e6da73c6e7348f Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:57:05 -0400 Subject: [PATCH 13/15] Add Composer script shortcuts to simplify testing --- composer.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/composer.json b/composer.json index 8a12e42..7dcc1a2 100644 --- a/composer.json +++ b/composer.json @@ -45,5 +45,17 @@ "branch-alias": { "dev-master": "2.0-dev" } + }, + "scripts": { + "phpcs": "phpcs", + "phpstan": "phpstan analyse", + "phpunit": "phpunit --no-coverage", + "psalm": "psalm", + "test": [ + "@phpcs", + "@phpstan", + "@psalm", + "@phpunit" + ] } } From 900ac8c2cabdf144d4404c737af3626aafc5499c Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 11:58:56 -0400 Subject: [PATCH 14/15] Add CONTRIBUTING.md guide --- .github/CONTRIBUTING.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..665dc6c --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. We accept contributions via Pull Requests on [GitHub](https://github.com/dflydev/dflydev-dot-access-data). + +## Pull Requests + +- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - The easiest way to apply the conventions is to run `./vendor/bin/phpcbf`. + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Tests must pass** - All automated tests, including things like code style checks, but be passing before we'll consider merging the change. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. + +- **Create feature branches** - Don't ask us to pull from your default branch. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + + +## Running Tests + +``` bash +$ composer test +``` + + +**Happy coding**! From 28e715541498b606bb0504c4b0f899b16c883dd4 Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 19 Sep 2020 12:41:47 -0400 Subject: [PATCH 15/15] Fix code coverage on PHP 7.1 --- .github/workflows/tests.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bc60942..60c38ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,10 +28,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4'] - coverage: [true] + php: ['7.2', '7.3', '7.4'] + coverage: [pcov] composer-flags: [''] include: + - php: '7.1' + coverage: xdebug + composer-flags: '' - php: '8.0' coverage: false composer-flags: '--ignore-platform-req=php' @@ -43,7 +46,7 @@ jobs: with: php-version: ${{ matrix.php }} extensions: curl - coverage: pcov + coverage: ${{ matrix.coverage }} tools: composer:v2 - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" @@ -55,10 +58,10 @@ jobs: - run: composer update --no-progress ${{ matrix.composer-flags }} - run: vendor/bin/phpunit --no-coverage - if: ${{ !matrix.coverage }} + if: ${{ matrix.coverage == 'none' }} - run: vendor/bin/phpunit --coverage-text - if: ${{ matrix.coverage }} + if: ${{ matrix.coverage != 'none' }} phpstan: name: PHPStan