* coding style fixes

This commit is contained in:
Danyi Dávid 2021-02-20 20:55:17 +01:00
parent e9f28022c6
commit 2409ccfaaf
28 changed files with 822 additions and 487 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/.idea /.idea
/vendor/ /vendor/
/.phpcs-cache

View File

@ -25,11 +25,15 @@
} }
], ],
"require-dev": { "require-dev": {
"phan/phan": "^4.0" "phan/phan": "^4.0",
"squizlabs/php_codesniffer": "^3.5.8",
"laminas/laminas-coding-standard": "^2.1.4"
}, },
"scripts": { "scripts": {
"phan": "phan", "phan": "phan",
"phan-init": "phan --init" "phan-init": "phan --init",
"cs-check": "phpcs",
"cs-fix": "phpcbf"
}, },
"extra": { "extra": {
"laminas": { "laminas": {

544
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "25e1f2c374a9f4e31b1efbaf7c8e5115", "content-hash": "2ddfae5af0f6b6f4051f0c284930eaa5",
"packages": [ "packages": [
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
@ -117,16 +117,16 @@
}, },
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
"version": "1.11.1", "version": "1.12.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/annotations.git", "url": "https://github.com/doctrine/annotations.git",
"reference": "ce77a7ba1770462cd705a91a151b6c3746f9c6ad" "reference": "ebec9b1708c95d7602245c8172773f6b4e0c3be1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/ce77a7ba1770462cd705a91a151b6c3746f9c6ad", "url": "https://api.github.com/repos/doctrine/annotations/zipball/ebec9b1708c95d7602245c8172773f6b4e0c3be1",
"reference": "ce77a7ba1770462cd705a91a151b6c3746f9c6ad", "reference": "ebec9b1708c95d7602245c8172773f6b4e0c3be1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -141,11 +141,6 @@
"phpunit/phpunit": "^7.5 || ^9.1.5" "phpunit/phpunit": "^7.5 || ^9.1.5"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.11.x-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations"
@ -186,9 +181,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/doctrine/annotations/issues", "issues": "https://github.com/doctrine/annotations/issues",
"source": "https://github.com/doctrine/annotations/tree/1.11.1" "source": "https://github.com/doctrine/annotations/tree/1.12.0"
}, },
"time": "2020-10-26T10:28:16+00:00" "time": "2021-02-14T13:22:18+00:00"
}, },
{ {
"name": "doctrine/cache", "name": "doctrine/cache",
@ -1289,16 +1284,16 @@
}, },
{ {
"name": "friendsofphp/proxy-manager-lts", "name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.2", "version": "v1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/FriendsOfPHP/proxy-manager-lts.git", "url": "https://github.com/FriendsOfPHP/proxy-manager-lts.git",
"reference": "4a66e4e0d3279d3bb3722963b4294331fabe15bc" "reference": "121af47c9aee9c03031bdeca3fac0540f59aa5c3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/4a66e4e0d3279d3bb3722963b4294331fabe15bc", "url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/121af47c9aee9c03031bdeca3fac0540f59aa5c3",
"reference": "4a66e4e0d3279d3bb3722963b4294331fabe15bc", "reference": "121af47c9aee9c03031bdeca3fac0540f59aa5c3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1355,7 +1350,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/FriendsOfPHP/proxy-manager-lts/issues", "issues": "https://github.com/FriendsOfPHP/proxy-manager-lts/issues",
"source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.2" "source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.3"
}, },
"funding": [ "funding": [
{ {
@ -1367,7 +1362,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-04T11:21:26+00:00" "time": "2021-01-14T21:52:44+00:00"
}, },
{ {
"name": "laminas/laminas-code", "name": "laminas/laminas-code",
@ -1836,16 +1831,16 @@
}, },
{ {
"name": "laminas/laminas-servicemanager", "name": "laminas/laminas-servicemanager",
"version": "3.6.0", "version": "3.6.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laminas/laminas-servicemanager.git", "url": "https://github.com/laminas/laminas-servicemanager.git",
"reference": "0c1ec25ff486d690c8aa8aeb93f560dab593aa78" "reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/0c1ec25ff486d690c8aa8aeb93f560dab593aa78", "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/b1445e1a7077c21b0fad0974a1b7a11b9dbe0828",
"reference": "0c1ec25ff486d690c8aa8aeb93f560dab593aa78", "reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1919,7 +1914,7 @@
"type": "community_bridge" "type": "community_bridge"
} }
], ],
"time": "2021-01-10T15:50:33+00:00" "time": "2021-02-03T08:44:41+00:00"
}, },
{ {
"name": "laminas/laminas-stdlib", "name": "laminas/laminas-stdlib",
@ -1981,16 +1976,16 @@
}, },
{ {
"name": "laminas/laminas-validator", "name": "laminas/laminas-validator",
"version": "2.14.0", "version": "2.14.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laminas/laminas-validator.git", "url": "https://github.com/laminas/laminas-validator.git",
"reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e" "reference": "e370c4695db1c81e6dfad38d8c4dbdb37b23d776"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-validator/zipball/8da5e20ed7b2b8101c1de68ca8dc0180210ed23e", "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/e370c4695db1c81e6dfad38d8c4dbdb37b23d776",
"reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e", "reference": "e370c4695db1c81e6dfad38d8c4dbdb37b23d776",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2069,7 +2064,7 @@
"type": "community_bridge" "type": "community_bridge"
} }
], ],
"time": "2021-01-07T16:07:31+00:00" "time": "2021-01-24T20:45:49+00:00"
}, },
{ {
"name": "laminas/laminas-zendframework-bridge", "name": "laminas/laminas-zendframework-bridge",
@ -2246,16 +2241,16 @@
}, },
{ {
"name": "symfony/console", "name": "symfony/console",
"version": "v5.2.1", "version": "v5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/console.git", "url": "https://github.com/symfony/console.git",
"reference": "47c02526c532fb381374dab26df05e7313978976" "reference": "89d4b176d12a2946a1ae4e34906a025b7b6b135a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/47c02526c532fb381374dab26df05e7313978976", "url": "https://api.github.com/repos/symfony/console/zipball/89d4b176d12a2946a1ae4e34906a025b7b6b135a",
"reference": "47c02526c532fb381374dab26df05e7313978976", "reference": "89d4b176d12a2946a1ae4e34906a025b7b6b135a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2314,7 +2309,7 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony Console Component", "description": "Eases the creation of beautiful and testable command line interfaces",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"keywords": [ "keywords": [
"cli", "cli",
@ -2323,7 +2318,7 @@
"terminal" "terminal"
], ],
"support": { "support": {
"source": "https://github.com/symfony/console/tree/v5.2.1" "source": "https://github.com/symfony/console/tree/v5.2.3"
}, },
"funding": [ "funding": [
{ {
@ -2339,20 +2334,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-12-18T08:03:05+00:00" "time": "2021-01-28T22:06:19+00:00"
}, },
{ {
"name": "symfony/filesystem", "name": "symfony/filesystem",
"version": "v5.2.1", "version": "v5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/filesystem.git", "url": "https://github.com/symfony/filesystem.git",
"reference": "fa8f8cab6b65e2d99a118e082935344c5ba8c60d" "reference": "262d033b57c73e8b59cd6e68a45c528318b15038"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/fa8f8cab6b65e2d99a118e082935344c5ba8c60d", "url": "https://api.github.com/repos/symfony/filesystem/zipball/262d033b57c73e8b59cd6e68a45c528318b15038",
"reference": "fa8f8cab6b65e2d99a118e082935344c5ba8c60d", "reference": "262d033b57c73e8b59cd6e68a45c528318b15038",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2382,10 +2377,10 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony Filesystem Component", "description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/filesystem/tree/v5.2.1" "source": "https://github.com/symfony/filesystem/tree/v5.2.3"
}, },
"funding": [ "funding": [
{ {
@ -2401,11 +2396,11 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-11-30T17:05:38+00:00" "time": "2021-01-27T10:01:46+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
@ -2464,7 +2459,7 @@
"portable" "portable"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2484,16 +2479,16 @@
}, },
{ {
"name": "symfony/polyfill-intl-grapheme", "name": "symfony/polyfill-intl-grapheme",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "267a9adeb8ecb8071040a740930e077cdfb987af" "reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/267a9adeb8ecb8071040a740930e077cdfb987af", "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/5601e09b69f26c1828b13b6bb87cb07cddba3170",
"reference": "267a9adeb8ecb8071040a740930e077cdfb987af", "reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2545,7 +2540,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2561,20 +2556,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-07T16:49:33+00:00" "time": "2021-01-22T09:19:47+00:00"
}, },
{ {
"name": "symfony/polyfill-intl-normalizer", "name": "symfony/polyfill-intl-normalizer",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "6e971c891537eb617a00bb07a43d182a6915faba" "reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/6e971c891537eb617a00bb07a43d182a6915faba", "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/43a0283138253ed1d48d352ab6d0bdb3f809f248",
"reference": "6e971c891537eb617a00bb07a43d182a6915faba", "reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2629,7 +2624,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2645,20 +2640,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-07T17:09:11+00:00" "time": "2021-01-22T09:19:47+00:00"
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13" "reference": "5232de97ee3b75b0360528dae24e73db49566ab1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f377a3dd1fde44d37b9831d68dc8dea3ffd28e13", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1",
"reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13", "reference": "5232de97ee3b75b0360528dae24e73db49566ab1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2709,7 +2704,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2725,11 +2720,11 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-07T16:49:33+00:00" "time": "2021-01-22T09:19:47+00:00"
}, },
{ {
"name": "symfony/polyfill-php73", "name": "symfony/polyfill-php73",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php73.git", "url": "https://github.com/symfony/polyfill-php73.git",
@ -2788,7 +2783,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-php73/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2808,7 +2803,7 @@
}, },
{ {
"name": "symfony/polyfill-php80", "name": "symfony/polyfill-php80",
"version": "v1.22.0", "version": "v1.22.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php80.git", "url": "https://github.com/symfony/polyfill-php80.git",
@ -2871,7 +2866,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.22.0" "source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1"
}, },
"funding": [ "funding": [
{ {
@ -2970,16 +2965,16 @@
}, },
{ {
"name": "symfony/stopwatch", "name": "symfony/stopwatch",
"version": "v5.2.1", "version": "v5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/stopwatch.git", "url": "https://github.com/symfony/stopwatch.git",
"reference": "2b105c0354f39a63038a1d8bf776ee92852813af" "reference": "b12274acfab9d9850c52583d136a24398cdf1a0c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/2b105c0354f39a63038a1d8bf776ee92852813af", "url": "https://api.github.com/repos/symfony/stopwatch/zipball/b12274acfab9d9850c52583d136a24398cdf1a0c",
"reference": "2b105c0354f39a63038a1d8bf776ee92852813af", "reference": "b12274acfab9d9850c52583d136a24398cdf1a0c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3009,10 +3004,10 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony Stopwatch Component", "description": "Provides a way to profile code",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/stopwatch/tree/v5.2.1" "source": "https://github.com/symfony/stopwatch/tree/v5.2.3"
}, },
"funding": [ "funding": [
{ {
@ -3028,20 +3023,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-11-01T16:14:45+00:00" "time": "2021-01-27T10:15:41+00:00"
}, },
{ {
"name": "symfony/string", "name": "symfony/string",
"version": "v5.2.1", "version": "v5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/string.git", "url": "https://github.com/symfony/string.git",
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed" "reference": "c95468897f408dd0aca2ff582074423dd0455122"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed", "url": "https://api.github.com/repos/symfony/string/zipball/c95468897f408dd0aca2ff582074423dd0455122",
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed", "reference": "c95468897f408dd0aca2ff582074423dd0455122",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3084,7 +3079,7 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony String component", "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"keywords": [ "keywords": [
"grapheme", "grapheme",
@ -3095,7 +3090,7 @@
"utf8" "utf8"
], ],
"support": { "support": {
"source": "https://github.com/symfony/string/tree/v5.2.1" "source": "https://github.com/symfony/string/tree/v5.2.3"
}, },
"funding": [ "funding": [
{ {
@ -3111,7 +3106,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-12-05T07:33:16+00:00" "time": "2021-01-25T15:14:59+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
@ -3260,26 +3255,96 @@
"time": "2020-11-13T08:04:11+00:00" "time": "2020-11-13T08:04:11+00:00"
}, },
{ {
"name": "felixfbecker/advanced-json-rpc", "name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v3.1.2", "version": "v0.7.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/felixfbecker/php-advanced-json-rpc.git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
"reference": "804ee564f1c7f0bc160d755fc5bdd17a04545070" "reference": "fe390591e0241955f22eb9ba327d137e501c771c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/804ee564f1c7f0bc160d755fc5bdd17a04545070", "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c",
"reference": "804ee564f1c7f0bc160d755fc5bdd17a04545070", "reference": "fe390591e0241955f22eb9ba327d137e501c771c",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=5.3",
"squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0"
},
"require-dev": {
"composer/composer": "*",
"phpcompatibility/php-compatibility": "^9.0",
"sensiolabs/security-checker": "^4.1.0"
},
"type": "composer-plugin",
"extra": {
"class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
},
"autoload": {
"psr-4": {
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Franck Nijhof",
"email": "franck.nijhof@dealerdirect.com",
"homepage": "http://www.frenck.nl",
"role": "Developer / IT Manager"
}
],
"description": "PHP_CodeSniffer Standards Composer Installer Plugin",
"homepage": "http://www.dealerdirect.com",
"keywords": [
"PHPCodeSniffer",
"PHP_CodeSniffer",
"code quality",
"codesniffer",
"composer",
"installer",
"phpcs",
"plugin",
"qa",
"quality",
"standard",
"standards",
"style guide",
"stylecheck",
"tests"
],
"support": {
"issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
"source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
},
"time": "2020-12-07T18:04:37+00:00"
},
{
"name": "felixfbecker/advanced-json-rpc",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/felixfbecker/php-advanced-json-rpc.git",
"reference": "06f0b06043c7438959dbdeed8bb3f699a19be22e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/06f0b06043c7438959dbdeed8bb3f699a19be22e",
"reference": "06f0b06043c7438959dbdeed8bb3f699a19be22e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"netresearch/jsonmapper": "^1.0 || ^2.0", "netresearch/jsonmapper": "^1.0 || ^2.0",
"php": ">=7.0", "php": "^7.1 || ^8.0",
"phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0.0" "phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^6.0.0" "phpunit/phpunit": "^7.0 || ^8.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -3300,9 +3365,63 @@
"description": "A more advanced JSONRPC implementation", "description": "A more advanced JSONRPC implementation",
"support": { "support": {
"issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues", "issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues",
"source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/v3.1.2" "source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/v3.2.0"
}, },
"time": "2021-01-10T13:07:47+00:00" "time": "2021-01-10T17:48:47+00:00"
},
{
"name": "laminas/laminas-coding-standard",
"version": "2.1.4",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-coding-standard.git",
"reference": "d75f1acf615232e108da2d2cf5a7df3e527b8f38"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/d75f1acf615232e108da2d2cf5a7df3e527b8f38",
"reference": "d75f1acf615232e108da2d2cf5a7df3e527b8f38",
"shasum": ""
},
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
"laminas/laminas-zendframework-bridge": "^1.0",
"php": "^7.3 || ~8.0.0",
"slevomat/coding-standard": "^6.4.1",
"squizlabs/php_codesniffer": "^3.5.8",
"webimpress/coding-standard": "^1.1.6"
},
"type": "phpcodesniffer-standard",
"autoload": {
"psr-4": {
"LaminasCodingStandard\\": "src/LaminasCodingStandard/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Laminas Coding Standard",
"homepage": "https://laminas.dev",
"keywords": [
"Coding Standard",
"laminas"
],
"support": {
"chat": "https://laminas.dev/chat",
"docs": "https://docs.laminas.dev/laminas-coding-standard/",
"forum": "https://discourse.laminas.dev",
"issues": "https://github.com/laminas/laminas-coding-standard/issues",
"rss": "https://github.com/laminas/laminas-coding-standard/releases.atom",
"source": "https://github.com/laminas/laminas-coding-standard"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2020-10-26T07:33:05+00:00"
}, },
{ {
"name": "microsoft/tolerant-php-parser", "name": "microsoft/tolerant-php-parser",
@ -3402,16 +3521,16 @@
}, },
{ {
"name": "phan/phan", "name": "phan/phan",
"version": "4.0.2", "version": "4.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phan/phan.git", "url": "https://github.com/phan/phan.git",
"reference": "2e5f16a17aa909c91397c6fbba0309b4fef0df53" "reference": "95171b8a89ff2433e7ebc27d8a133743f7d78d3b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phan/phan/zipball/2e5f16a17aa909c91397c6fbba0309b4fef0df53", "url": "https://api.github.com/repos/phan/phan/zipball/95171b8a89ff2433e7ebc27d8a133743f7d78d3b",
"reference": "2e5f16a17aa909c91397c6fbba0309b4fef0df53", "reference": "95171b8a89ff2433e7ebc27d8a133743f7d78d3b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3473,9 +3592,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/phan/phan/issues", "issues": "https://github.com/phan/phan/issues",
"source": "https://github.com/phan/phan/tree/4.0.2" "source": "https://github.com/phan/phan/tree/4.0.3"
}, },
"time": "2021-01-09T21:32:36+00:00" "time": "2021-01-30T00:08:54+00:00"
}, },
{ {
"name": "phpdocumentor/reflection-common", "name": "phpdocumentor/reflection-common",
@ -3635,6 +3754,59 @@
}, },
"time": "2020-09-17T18:55:26+00:00" "time": "2020-09-17T18:55:26+00:00"
}, },
{
"name": "phpstan/phpdoc-parser",
"version": "0.4.9",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/98a088b17966bdf6ee25c8a4b634df313d8aa531",
"reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
"consistence/coding-standard": "^3.5",
"ergebnis/composer-normalize": "^2.0.2",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phing/phing": "^2.16.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.26",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^6.3",
"slevomat/coding-standard": "^4.7.2",
"symfony/process": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.4-dev"
}
},
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/master"
},
"time": "2020-08-03T20:32:43+00:00"
},
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.1.3", "version": "1.1.3",
@ -3751,17 +3923,189 @@
}, },
"time": "2020-10-03T11:02:22+00:00" "time": "2020-10-03T11:02:22+00:00"
}, },
{
"name": "slevomat/coding-standard",
"version": "6.4.1",
"source": {
"type": "git",
"url": "https://github.com/slevomat/coding-standard.git",
"reference": "696dcca217d0c9da2c40d02731526c1e25b65346"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/696dcca217d0c9da2c40d02731526c1e25b65346",
"reference": "696dcca217d0c9da2c40d02731526c1e25b65346",
"shasum": ""
},
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
"php": "^7.1 || ^8.0",
"phpstan/phpdoc-parser": "0.4.5 - 0.4.9",
"squizlabs/php_codesniffer": "^3.5.6"
},
"require-dev": {
"phing/phing": "2.16.3",
"php-parallel-lint/php-parallel-lint": "1.2.0",
"phpstan/phpstan": "0.12.48",
"phpstan/phpstan-deprecation-rules": "0.12.5",
"phpstan/phpstan-phpunit": "0.12.16",
"phpstan/phpstan-strict-rules": "0.12.5",
"phpunit/phpunit": "7.5.20|8.5.5|9.4.0"
},
"type": "phpcodesniffer-standard",
"extra": {
"branch-alias": {
"dev-master": "6.x-dev"
}
},
"autoload": {
"psr-4": {
"SlevomatCodingStandard\\": "SlevomatCodingStandard"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.",
"support": {
"issues": "https://github.com/slevomat/coding-standard/issues",
"source": "https://github.com/slevomat/coding-standard/tree/6.4.1"
},
"funding": [
{
"url": "https://github.com/kukulich",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard",
"type": "tidelift"
}
],
"time": "2020-10-05T12:39:37+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.5.8",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "9d583721a7157ee997f235f327de038e7ea6dac4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4",
"reference": "9d583721a7157ee997f235f327de038e7ea6dac4",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"bin": [
"bin/phpcs",
"bin/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
"keywords": [
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2020-10-23T02:01:07+00:00"
},
{
"name": "webimpress/coding-standard",
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/webimpress/coding-standard.git",
"reference": "fbeb31ee876b3c493779d3aa717ebb57ef258e6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webimpress/coding-standard/zipball/fbeb31ee876b3c493779d3aa717ebb57ef258e6a",
"reference": "fbeb31ee876b3c493779d3aa717ebb57ef258e6a",
"shasum": ""
},
"require": {
"php": "^7.3 || ^8.0",
"squizlabs/php_codesniffer": "^3.5.8"
},
"require-dev": {
"phpunit/phpunit": "^9.4.3"
},
"type": "phpcodesniffer-standard",
"extra": {
"dev-master": "1.2.x-dev",
"dev-develop": "1.3.x-dev"
},
"autoload": {
"psr-4": {
"WebimpressCodingStandard\\": "src/WebimpressCodingStandard/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"description": "Webimpress Coding Standard",
"keywords": [
"Coding Standard",
"PSR-2",
"phpcs",
"psr-12",
"webimpress"
],
"support": {
"issues": "https://github.com/webimpress/coding-standard/issues",
"source": "https://github.com/webimpress/coding-standard/tree/1.2.1"
},
"funding": [
{
"url": "https://github.com/michalbundyra",
"type": "github"
}
],
"time": "2021-01-11T18:13:55+00:00"
},
{ {
"name": "webmozart/assert", "name": "webmozart/assert",
"version": "1.9.1", "version": "1.9.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": "" "shasum": ""
}, },
@ -3799,8 +4143,8 @@
"validate" "validate"
], ],
"support": { "support": {
"issues": "https://github.com/webmozart/assert/issues", "issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozart/assert/tree/master" "source": "https://github.com/webmozarts/assert/tree/1.9.1"
}, },
"time": "2020-07-08T17:02:28+00:00" "time": "2020-07-08T17:02:28+00:00"
} }

19
phpcs.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<!-- Show progress -->
<arg value="p"/>
<!-- Paths to check -->
<file>src</file>
<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>

View File

@ -20,7 +20,6 @@ class ConfigProvider
* *
* To add a bit of a structure, each section is defined in a separate * To add a bit of a structure, each section is defined in a separate
* method which returns an array with its configuration. * method which returns an array with its configuration.
*
*/ */
public function __invoke(): array public function __invoke(): array
{ {

View File

@ -1,13 +1,15 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element; namespace DoctrineMezzioModule\Form\Element;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Laminas\Form\Element;
class ElementFactory class ElementFactory
{ {
public function __invoke(ContainerInterface $container, string $elementClass, array $options = []): Element
public function __invoke(ContainerInterface $container, string $elementClass, array $options = [])
{ {
$em = $container->get('doctrine.entity_manager.orm_default'); $em = $container->get('doctrine.entity_manager.orm_default');
/** @var ObjectSelect|ObjectRadio|ObjectMultiCheckbox $element */ /** @var ObjectSelect|ObjectRadio|ObjectMultiCheckbox $element */

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element\Exception;
use InvalidArgumentException;
class CompositeIdentifierException extends InvalidArgumentException
{
}

View File

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element\Exception; namespace DoctrineMezzioModule\Form\Element\Exception;
use InvalidArgumentException; use InvalidArgumentException;

View File

@ -1,21 +1,20 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element; namespace DoctrineMezzioModule\Form\Element;
use Laminas\Form\Element\MultiCheckbox; use Laminas\Form\Element\MultiCheckbox;
use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\ArrayUtils;
use Traversable; use Traversable;
use function array_map;
use function is_array;
class ObjectMultiCheckbox extends MultiCheckbox class ObjectMultiCheckbox extends MultiCheckbox
{ {
/** protected Proxy $proxy;
* @var Proxy
*/
protected $proxy;
/**
* @return Proxy
*/
public function getProxy(): Proxy public function getProxy(): Proxy
{ {
if (null === $this->proxy) { if (null === $this->proxy) {
@ -52,7 +51,7 @@ class ObjectMultiCheckbox extends MultiCheckbox
{ {
if ($value instanceof Traversable) { if ($value instanceof Traversable) {
$value = ArrayUtils::iteratorToArray($value); $value = ArrayUtils::iteratorToArray($value);
} elseif ($value == null) { } elseif ($value === null) {
return parent::setValue([]); return parent::setValue([]);
} elseif (! is_array($value)) { } elseif (! is_array($value)) {
$value = (array) $value; $value = (array) $value;

View File

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element; namespace DoctrineMezzioModule\Form\Element;
use Laminas\Form\Element\Radio as RadioElement; use Laminas\Form\Element\Radio as RadioElement;
@ -7,14 +9,8 @@ use Traversable;
class ObjectRadio extends RadioElement class ObjectRadio extends RadioElement
{ {
/** protected Proxy $proxy;
* @var Proxy
*/
protected $proxy;
/**
* @return Proxy
*/
public function getProxy(): Proxy public function getProxy(): Proxy
{ {
if (null === $this->proxy) { if (null === $this->proxy) {

View File

@ -1,21 +1,20 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element; namespace DoctrineMezzioModule\Form\Element;
use Laminas\Form\Element\Select as SelectElement; use Laminas\Form\Element\Select as SelectElement;
use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\ArrayUtils;
use Traversable; use Traversable;
use function array_map;
use function is_array;
class ObjectSelect extends SelectElement class ObjectSelect extends SelectElement
{ {
/** protected Proxy $proxy;
* @var Proxy
*/
protected $proxy;
/**
* @return Proxy
*/
public function getProxy(): Proxy public function getProxy(): Proxy
{ {
if (null === $this->proxy) { if (null === $this->proxy) {
@ -55,7 +54,7 @@ class ObjectSelect extends SelectElement
if (true === $multiple || 'multiple' === $multiple) { if (true === $multiple || 'multiple' === $multiple) {
if ($value instanceof Traversable) { if ($value instanceof Traversable) {
$value = ArrayUtils::iteratorToArray($value); $value = ArrayUtils::iteratorToArray($value);
} elseif ($value == null) { } elseif ($value === null) {
return parent::setValue([]); return parent::setValue([]);
} elseif (! is_array($value)) { } elseif (! is_array($value)) {
$value = (array) $value; $value = (array) $value;

View File

@ -1,87 +1,75 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Form\Element; namespace DoctrineMezzioModule\Form\Element;
use Doctrine\Inflector\InflectorFactory;
use ReflectionException;
use Traversable;
use ReflectionMethod;
use RuntimeException;
use InvalidArgumentException;
use Laminas\Stdlib\Guard\ArrayOrTraversableGuardTrait;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Mapping\Entity;
use DoctrineMezzioModule\Form\Element\Exception\CompositeIdentifierException;
use DoctrineMezzioModule\Form\Element\Exception\InvalidRepositoryResultException;
use Exception;
use InvalidArgumentException;
use Laminas\Stdlib\Guard\ArrayOrTraversableGuardTrait;
use ReflectionException;
use ReflectionMethod;
use RuntimeException;
use Traversable;
use function array_change_key_case;
use function array_key_exists;
use function array_shift;
use function call_user_func;
use function count;
use function current;
use function get_class;
use function gettype;
use function is_callable;
use function is_object;
use function is_string;
use function method_exists;
use function sprintf;
use function strtolower;
use function trim;
class Proxy class Proxy
{ {
use ArrayOrTraversableGuardTrait; use ArrayOrTraversableGuardTrait;
/** /** @var array|Traversable */
* @var array|Traversable
*/
protected $objects; protected $objects;
/** protected string $targetClass;
* @var string
*/
protected $targetClass;
/** /** @var array */
* @var array protected array $valueOptions = [];
*/
protected $valueOptions = [];
/** /** @var array */
* @var array protected array $findMethod = [];
*/
protected $findMethod = [];
/** protected string $property;
* @var string
*/
protected $property;
/** /** @var array */
* @var array protected array $optionAttributes = [];
*/
protected $option_attributes = [];
/** /** @var callable $labelGenerator A callable used to create a label based on an item in the collection an Entity */
* @var callable $labelGenerator A callable used to create a label based on an item in the collection an Entity
*/
protected $labelGenerator; protected $labelGenerator;
/** protected ?bool $isMethod;
* @var bool|null
*/
protected $isMethod;
/** protected ObjectManager $objectManager;
* @var ObjectManager
*/
protected $objectManager;
/** protected bool $displayEmptyItem = false;
* @var bool
*/
protected $displayEmptyItem = false;
/** protected string $emptyItemLabel = '';
* @var string
*/
protected $emptyItemLabel = '';
/** protected ?string $optgroupIdentifier;
* @var string|null
*/
protected $optgroupIdentifier;
/** protected ?string $optgroupDefault;
* @var string|null
*/
protected $optgroupDefault;
public function setOptions($options) public function setOptions(array $options)
{ {
if (isset($options['object_manager'])) { if (isset($options['object_manager'])) {
$this->setObjectManager($options['object_manager']); $this->setObjectManager($options['object_manager']);
@ -128,7 +116,10 @@ class Proxy
} }
} }
public function getValueOptions() /**
* @throws ReflectionException
*/
public function getValueOptions(): array
{ {
if (empty($this->valueOptions)) { if (empty($this->valueOptions)) {
$this->loadValueOptions(); $this->loadValueOptions();
@ -139,6 +130,7 @@ class Proxy
/** /**
* @return array|Traversable * @return array|Traversable
* @throws ReflectionException
*/ */
public function getObjects() public function getObjects()
{ {
@ -149,21 +141,14 @@ class Proxy
/** /**
* Set the label for the empty option * Set the label for the empty option
*
* @param string $emptyItemLabel
*
* @return Proxy
*/ */
public function setEmptyItemLabel($emptyItemLabel): Proxy public function setEmptyItemLabel(string $emptyItemLabel): Proxy
{ {
$this->emptyItemLabel = $emptyItemLabel; $this->emptyItemLabel = $emptyItemLabel;
return $this; return $this;
} }
/**
* @return string
*/
public function getEmptyItemLabel(): string public function getEmptyItemLabel(): string
{ {
return $this->emptyItemLabel; return $this->emptyItemLabel;
@ -174,23 +159,19 @@ class Proxy
*/ */
public function getOptionAttributes(): array public function getOptionAttributes(): array
{ {
return $this->option_attributes; return $this->optionAttributes;
} }
/** /**
* @param array $option_attributes * @param array $optionAttributes
*/ */
public function setOptionAttributes(array $option_attributes) public function setOptionAttributes(array $optionAttributes)
{ {
$this->option_attributes = $option_attributes; $this->optionAttributes = $optionAttributes;
} }
/** /**
* Set a flag, whether to include the empty option at the beginning or not * Set a flag, whether to include the empty option at the beginning or not
*
* @param boolean $displayEmptyItem
*
* @return Proxy
*/ */
public function setDisplayEmptyItem(bool $displayEmptyItem): Proxy public function setDisplayEmptyItem(bool $displayEmptyItem): Proxy
{ {
@ -199,9 +180,6 @@ class Proxy
return $this; return $this;
} }
/**
* @return boolean
*/
public function getDisplayEmptyItem(): bool public function getDisplayEmptyItem(): bool
{ {
return $this->displayEmptyItem; return $this->displayEmptyItem;
@ -209,10 +187,6 @@ class Proxy
/** /**
* Set the object manager * Set the object manager
*
* @param ObjectManager $objectManager
*
* @return Proxy
*/ */
public function setObjectManager(ObjectManager $objectManager): Proxy public function setObjectManager(ObjectManager $objectManager): Proxy
{ {
@ -223,8 +197,6 @@ class Proxy
/** /**
* Get the object manager * Get the object manager
*
* @return ObjectManager
*/ */
public function getObjectManager(): ObjectManager public function getObjectManager(): ObjectManager
{ {
@ -233,10 +205,6 @@ class Proxy
/** /**
* Set the FQCN of the target object * Set the FQCN of the target object
*
* @param string $targetClass
*
* @return Proxy
*/ */
public function setTargetClass(string $targetClass): Proxy public function setTargetClass(string $targetClass): Proxy
{ {
@ -247,8 +215,6 @@ class Proxy
/** /**
* Get the target class * Get the target class
*
* @return string
*/ */
public function getTargetClass(): string public function getTargetClass(): string
{ {
@ -257,10 +223,6 @@ class Proxy
/** /**
* Set the property to use as the label in the options * Set the property to use as the label in the options
*
* @param string $property
*
* @return Proxy
*/ */
public function setProperty(string $property): Proxy public function setProperty(string $property): Proxy
{ {
@ -269,9 +231,6 @@ class Proxy
return $this; return $this;
} }
/**
* @return string
*/
public function getProperty(): string public function getProperty(): string
{ {
return $this->property; return $this->property;
@ -281,7 +240,6 @@ class Proxy
* Set the label generator callable that is responsible for generating labels for the items in the collection * Set the label generator callable that is responsible for generating labels for the items in the collection
* *
* @param callable $callable A callable used to create a label based off of an Entity * @param callable $callable A callable used to create a label based off of an Entity
*
* @return void * @return void
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
@ -296,41 +254,26 @@ class Proxy
$this->labelGenerator = $callable; $this->labelGenerator = $callable;
} }
/**
* @return callable|null
*/
public function getLabelGenerator(): ?callable public function getLabelGenerator(): ?callable
{ {
return $this->labelGenerator; return $this->labelGenerator;
} }
/**
* @return string|null
*/
public function getOptgroupIdentifier(): ?string public function getOptgroupIdentifier(): ?string
{ {
return $this->optgroupIdentifier; return $this->optgroupIdentifier;
} }
/**
* @param string $optgroupIdentifier
*/
public function setOptgroupIdentifier(string $optgroupIdentifier) public function setOptgroupIdentifier(string $optgroupIdentifier)
{ {
$this->optgroupIdentifier = (string) $optgroupIdentifier; $this->optgroupIdentifier = (string) $optgroupIdentifier;
} }
/**
* @return string|null
*/
public function getOptgroupDefault(): ?string public function getOptgroupDefault(): ?string
{ {
return $this->optgroupDefault; return $this->optgroupDefault;
} }
/**
* @param string $optgroupDefault
*/
public function setOptgroupDefault(string $optgroupDefault) public function setOptgroupDefault(string $optgroupDefault)
{ {
$this->optgroupDefault = (string) $optgroupDefault; $this->optgroupDefault = (string) $optgroupDefault;
@ -338,10 +281,6 @@ class Proxy
/** /**
* Set if the property is a method to use as the label in the options * Set if the property is a method to use as the label in the options
*
* @param boolean $method
*
* @return Proxy
*/ */
public function setIsMethod(bool $method): Proxy public function setIsMethod(bool $method): Proxy
{ {
@ -361,8 +300,6 @@ class Proxy
/** Set the findMethod property to specify the method to use on repository /** Set the findMethod property to specify the method to use on repository
* *
* @param array $findMethod * @param array $findMethod
*
* @return Proxy
*/ */
public function setFindMethod(array $findMethod): Proxy public function setFindMethod(array $findMethod): Proxy
{ {
@ -382,9 +319,7 @@ class Proxy
} }
/** /**
* @param $targetEntity * @param Entity $targetEntity
*
* @return string|null
*/ */
protected function generateLabel($targetEntity): ?string protected function generateLabel($targetEntity): ?string
{ {
@ -396,8 +331,7 @@ class Proxy
} }
/** /**
* @param $value * @param Collection|Entity $value
*
* @return array|mixed|object * @return array|mixed|object
* @throws RuntimeException * @throws RuntimeException
*/ */
@ -429,7 +363,7 @@ class Proxy
// TODO: handle composite (multiple) identifiers // TODO: handle composite (multiple) identifiers
if (null !== $identifier && count($identifier) > 1) { if (null !== $identifier && count($identifier) > 1) {
//$value = $key; throw new CompositeIdentifierException("Can't handle composite identifiers");
} else { } else {
$value = current($metadata->getIdentifierValues($value)); $value = current($metadata->getIdentifierValues($value));
} }
@ -443,10 +377,10 @@ class Proxy
* Load objects * Load objects
* *
* @return void * @return void
* @throws Exception\InvalidRepositoryResultException * @throws InvalidRepositoryResultException
* @throws ReflectionException * @throws ReflectionException
* @throws RuntimeException * @throws RuntimeException
* @throws \Exception * @throws Exception
*/ */
protected function loadObjects() protected function loadObjects()
{ {
@ -513,8 +447,8 @@ class Proxy
/** /**
* Load value options * Load value options
* *
* @throws RuntimeException
* @return void * @return void
* @throws RuntimeException|ReflectionException
*/ */
protected function loadValueOptions() protected function loadValueOptions()
{ {
@ -540,7 +474,7 @@ class Proxy
if (null !== ($generatedLabel = $this->generateLabel($object))) { if (null !== ($generatedLabel = $this->generateLabel($object))) {
$label = $generatedLabel; $label = $generatedLabel;
} elseif ($property = $this->property) { } elseif ($property = $this->property) {
if ($this->isMethod == false && ! $metadata->hasField($property)) { if ($this->isMethod === false && ! $metadata->hasField($property)) {
throw new RuntimeException( throw new RuntimeException(
sprintf( sprintf(
'Property "%s" could not be found in object "%s"', 'Property "%s" could not be found in object "%s"',
@ -604,7 +538,8 @@ class Proxy
} }
// If no optgroup_identifier has been configured, apply default handling and continue // If no optgroup_identifier has been configured, apply default handling and continue
if (is_null($this->getOptgroupIdentifier())) { $optGroupId = $this->getOptgroupIdentifier();
if ($optGroupId === null) {
$options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes]; $options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes];
continue; continue;
@ -612,7 +547,7 @@ class Proxy
// optgroup_identifier found, handle grouping // optgroup_identifier found, handle grouping
$inflector = InflectorFactory::create()->build(); $inflector = InflectorFactory::create()->build();
$optgroupGetter = 'get' . $inflector->classify($this->getOptgroupIdentifier()); $optgroupGetter = 'get' . $inflector->classify($optGroupId);
if (! is_callable([$object, $optgroupGetter])) { if (! is_callable([$object, $optgroupGetter])) {
throw new RuntimeException( throw new RuntimeException(
@ -623,7 +558,7 @@ class Proxy
$optgroup = $object->{$optgroupGetter}(); $optgroup = $object->{$optgroupGetter}();
// optgroup_identifier contains a valid group-name. Handle default grouping. // optgroup_identifier contains a valid group-name. Handle default grouping.
if (false === is_null($optgroup) && trim($optgroup) !== '') { if ($optgroup !== null && trim($optgroup) !== '') {
$options[$optgroup]['label'] = $optgroup; $options[$optgroup]['label'] = $optgroup;
$options[$optgroup]['options'][] = [ $options[$optgroup]['options'][] = [
'label' => $label, 'label' => $label,
@ -637,7 +572,7 @@ class Proxy
$optgroupDefault = $this->getOptgroupDefault(); $optgroupDefault = $this->getOptgroupDefault();
// No optgroup_default has been provided. Line up without a group // No optgroup_default has been provided. Line up without a group
if (is_null($optgroupDefault)) { if ($optgroupDefault === null) {
$options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes]; $options[] = ['label' => $label, 'value' => $value, 'attributes' => $optionAttributes];
continue; continue;

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,21 +18,46 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator; namespace DoctrineMezzioModule\Hydrator;
use DateTime; use DateTime;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\InflectorFactory;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Exception; use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use Laminas\Hydrator\AbstractHydrator;
use Laminas\Hydrator\Filter\FilterProviderInterface;
use Laminas\Stdlib\ArrayUtils;
use ReflectionException; use ReflectionException;
use RuntimeException; use RuntimeException;
use Traversable; use Traversable;
use Laminas\Stdlib\ArrayUtils;
use Laminas\Hydrator\AbstractHydrator; use function array_filter;
use Laminas\Hydrator\Filter\FilterProviderInterface; use function array_flip;
use function array_intersect_key;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function ctype_upper;
use function current;
use function get_class;
use function get_class_methods;
use function gettype;
use function in_array;
use function is_array;
use function is_int;
use function is_object;
use function is_string;
use function ltrim;
use function method_exists;
use function property_exists;
use function sprintf;
use function substr;
use function ucfirst;
/** /**
* This hydrator has been completely refactored for DoctrineModule 0.7.0. It provides an easy and powerful way * This hydrator has been completely refactored for DoctrineModule 0.7.0. It provides an easy and powerful way
@ -39,29 +65,19 @@ use Laminas\Hydrator\Filter\FilterProviderInterface;
* *
* Starting from DoctrineModule 0.8.0, the hydrator can be used multiple times with different objects * Starting from DoctrineModule 0.8.0, the hydrator can be used multiple times with different objects
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
class DoctrineObject extends AbstractHydrator class DoctrineObject extends AbstractHydrator
{ {
/**
* @var ObjectManager
*/
protected ObjectManager $objectManager; protected ObjectManager $objectManager;
/**
* @var ClassMetadata
*/
protected ClassMetadata $metadata; protected ClassMetadata $metadata;
/**
* @var bool
*/
protected bool $byValue = true; protected bool $byValue = true;
/** /**
* Constructor * Constructor
* *
@ -77,7 +93,6 @@ class DoctrineObject extends AbstractHydrator
/** /**
* Extract values from an object * Extract values from an object
* *
* @param object $object
* @return array * @return array
* @throws ReflectionException * @throws ReflectionException
*/ */
@ -96,8 +111,6 @@ class DoctrineObject extends AbstractHydrator
* Hydrate $object with the provided $data. * Hydrate $object with the provided $data.
* *
* @param array $data * @param array $data
* @param object $object
* @return object
* @throws ReflectionException * @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
@ -115,7 +128,6 @@ class DoctrineObject extends AbstractHydrator
/** /**
* Prepare the hydrator by adding strategies to every collection valued associations * Prepare the hydrator by adding strategies to every collection valued associations
* *
* @param object $object
* @return void * @return void
*/ */
protected function prepare(object $object) protected function prepare(object $object)
@ -167,7 +179,6 @@ class DoctrineObject extends AbstractHydrator
* Extract values from an object using a by-value logic (this means that it uses the entity * Extract values from an object using a by-value logic (this means that it uses the entity
* API, in this case, getters) * API, in this case, getters)
* *
* @param object $object
* @return array * @return array
* @throws RuntimeException * @throws RuntimeException
*/ */
@ -194,9 +205,11 @@ class DoctrineObject extends AbstractHydrator
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$getter(), $object); $data[$dataFieldName] = $this->extractValue($fieldName, $object->$getter(), $object);
} elseif (in_array($isser, $methods)) { } elseif (in_array($isser, $methods)) {
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$isser(), $object); $data[$dataFieldName] = $this->extractValue($fieldName, $object->$isser(), $object);
} elseif (substr($fieldName, 0, 2) === 'is' } elseif (
substr($fieldName, 0, 2) === 'is'
&& ctype_upper(substr($fieldName, 2, 1)) && ctype_upper(substr($fieldName, 2, 1))
&& in_array($fieldName, $methods)) { && in_array($fieldName, $methods)
) {
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$fieldName(), $object); $data[$dataFieldName] = $this->extractValue($fieldName, $object->$fieldName(), $object);
} }
@ -210,7 +223,6 @@ class DoctrineObject extends AbstractHydrator
* Extract values from an object using a by-reference logic (this means that values are * Extract values from an object using a by-reference logic (this means that values are
* directly fetched without using the public API of the entity, in this case, getters) * directly fetched without using the public API of the entity, in this case, getters)
* *
* @param object $object
* @return array * @return array
* @throws ReflectionException * @throws ReflectionException
*/ */
@ -242,8 +254,6 @@ class DoctrineObject extends AbstractHydrator
* case, setters) * case, setters)
* *
* @param array $data * @param array $data
* @param object $object
* @return object
* @throws RuntimeException|ReflectionException * @throws RuntimeException|ReflectionException
* @throws Exception * @throws Exception
*/ */
@ -272,7 +282,8 @@ class DoctrineObject extends AbstractHydrator
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data)); $value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
if (null === $value if (
null === $value
&& ! current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull() && ! current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
) { ) {
continue; continue;
@ -300,8 +311,6 @@ class DoctrineObject extends AbstractHydrator
* setters) * setters)
* *
* @param array $data * @param array $data
* @param object $object
* @return object
* @throws Exception * @throws Exception
*/ */
protected function hydrateByReference(array $data, object $object): object protected function hydrateByReference(array $data, object $object): object
@ -349,8 +358,6 @@ class DoctrineObject extends AbstractHydrator
* tricks like setting manually the existing id directly into the entity * tricks like setting manually the existing id directly into the entity
* *
* @param array $data The data that may contain identifiers keys * @param array $data The data that may contain identifiers keys
* @param object $object
* @return object
*/ */
protected function tryConvertArrayToObject(array $data, object $object): ?object protected function tryConvertArrayToObject(array $data, object $object): ?object
{ {
@ -381,22 +388,20 @@ class DoctrineObject extends AbstractHydrator
* and a target instance will be initialized and then hydrated. The hydrated * and a target instance will be initialized and then hydrated. The hydrated
* target will be returned. * target will be returned.
* *
* @param string $target
* @param mixed $value * @param mixed $value
* @return object
* @throws ReflectionException * @throws ReflectionException
*/ */
protected function toOne(string $target, $value): ?object protected function toOne(string $target, $value): ?object
{ {
$metadata = $this->objectManager->getClassMetadata($target); $metadata = $this->objectManager->getClassMetadata($target);
if (is_array($value) && array_keys($value) != $metadata->getIdentifier()) { if (is_array($value) && array_keys($value) !== $metadata->getIdentifier()) {
// $value is most likely an array of fieldset data // $value is most likely an array of fieldset data
$identifiers = array_intersect_key( $identifiers = array_intersect_key(
$value, $value,
array_flip($metadata->getIdentifier()) array_flip($metadata->getIdentifier())
); );
$object = $this->find($identifiers, $target) ?: new $target; $object = $this->find($identifiers, $target) ?: new $target();
return $this->hydrate($value, $object); return $this->hydrate($value, $object);
} }
@ -409,11 +414,8 @@ class DoctrineObject extends AbstractHydrator
* strategies that inherit from AbstractCollectionStrategy class, and that add or remove elements but without * strategies that inherit from AbstractCollectionStrategy class, and that add or remove elements but without
* changing the collection of the object * changing the collection of the object
* *
* @param object $object
* @param mixed $collectionName * @param mixed $collectionName
* @param string $target
* @param mixed $values * @param mixed $values
*
* @return void * @return void
* @throws InvalidArgumentException|ReflectionException * @throws InvalidArgumentException|ReflectionException
*/ */
@ -453,7 +455,7 @@ class DoctrineObject extends AbstractHydrator
} }
break; break;
case 'array': case 'array':
if (array_key_exists($field, $value) && $value[$field] != null) { if (array_key_exists($field, $value) && $value[$field] !== null) {
$find[$field] = $value[$field]; $find[$field] = $value[$field];
unset($value[$field]); // removed identifier from persistable data unset($value[$field]); // removed identifier from persistable data
} }
@ -466,9 +468,9 @@ class DoctrineObject extends AbstractHydrator
} }
if (! empty($find) && $found = $this->find($find, $target)) { if (! empty($find) && $found = $this->find($find, $target)) {
$collection[] = (is_array($value)) ? $this->hydrate($value, $found) : $found; $collection[] = is_array($value) ? $this->hydrate($value, $found) : $found;
} else { } else {
$collection[] = (is_array($value)) ? $this->hydrate($value, new $target) : new $target; $collection[] = is_array($value) ? $this->hydrate($value, new $target()) : new $target();
} }
} }
@ -494,7 +496,6 @@ class DoctrineObject extends AbstractHydrator
* Handle various type conversions that should be supported natively by Doctrine (like DateTime) * Handle various type conversions that should be supported natively by Doctrine (like DateTime)
* *
* @param mixed $value * @param mixed $value
* @param string $typeOfField
* @return DateTime|DateTimeImmutable|null * @return DateTime|DateTimeImmutable|null
* @throws Exception * @throws Exception
*/ */
@ -545,9 +546,6 @@ class DoctrineObject extends AbstractHydrator
* Find an object by a given target class and identifier * Find an object by a given target class and identifier
* *
* @param mixed $identifiers * @param mixed $identifiers
* @param string $targetClass
*
* @return object|null
*/ */
protected function find($identifiers, string $targetClass): ?object protected function find($identifiers, string $targetClass): ?object
{ {
@ -566,8 +564,6 @@ class DoctrineObject extends AbstractHydrator
* Verifies if a provided identifier is to be considered null * Verifies if a provided identifier is to be considered null
* *
* @param mixed $identifier * @param mixed $identifier
*
* @return bool
*/ */
private function isNullIdentifier($identifier): bool private function isNullIdentifier($identifier): bool
{ {
@ -591,10 +587,6 @@ class DoctrineObject extends AbstractHydrator
/** /**
* Applies the naming strategy if there is one set * Applies the naming strategy if there is one set
*
* @param string $field
*
* @return string
*/ */
protected function computeHydrateFieldName(string $field): string protected function computeHydrateFieldName(string $field): string
{ {
@ -606,10 +598,6 @@ class DoctrineObject extends AbstractHydrator
/** /**
* Applies the naming strategy if there is one set * Applies the naming strategy if there is one set
*
* @param string $field
*
* @return string
*/ */
protected function computeExtractFieldName(string $field): string protected function computeExtractFieldName(string $field): string
{ {

View File

@ -1,12 +1,13 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator; namespace DoctrineMezzioModule\Hydrator;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
class DoctrineObjectFactory class DoctrineObjectFactory
{ {
public function __invoke(ContainerInterface $container): DoctrineObject public function __invoke(ContainerInterface $container): DoctrineObject
{ {
$em = $container->get('doctrine.entity_manager.orm_default'); $em = $container->get('doctrine.entity_manager.orm_default');

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,17 +18,21 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Filter; namespace DoctrineMezzioModule\Hydrator\Filter;
use Laminas\Hydrator\Filter\FilterInterface; use Laminas\Hydrator\Filter\FilterInterface;
use function in_array;
use function is_array;
/** /**
* Provides a filter to restrict returned fields by whitelisting or * Provides a filter to restrict returned fields by whitelisting or
* blacklisting property names. * blacklisting property names.
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @author Liam O'Boyle <liam@ontheroad.net.nz> * @license MIT
*/ */
class PropertyName implements FilterInterface class PropertyName implements FilterInterface
{ {
@ -40,10 +45,8 @@ class PropertyName implements FilterInterface
/** /**
* Either an exclude or an include. * Either an exclude or an include.
*
* @var bool
*/ */
protected $exclude = null; protected ?bool $exclude = null;
/** /**
* @param string|array $properties The properties to exclude or include. * @param string|array $properties The properties to exclude or include.

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,42 +18,40 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy; namespace DoctrineMezzioModule\Hydrator\Strategy;
use InvalidArgumentException;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\ClassMetadata;
use InvalidArgumentException;
use Laminas\Hydrator\Strategy\StrategyInterface; use Laminas\Hydrator\Strategy\StrategyInterface;
use ReflectionException;
use function get_class;
use function is_object;
use function method_exists;
use function spl_object_hash;
use function sprintf;
use function strcmp;
use function ucfirst;
/** /**
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
abstract class AbstractCollectionStrategy implements StrategyInterface abstract class AbstractCollectionStrategy implements StrategyInterface
{ {
/** protected string $collectionName;
* @var string
*/
protected $collectionName;
/** protected ClassMetadata $metadata;
* @var ClassMetadata
*/
protected $metadata;
/**
* @var object
*/
protected $object;
protected object $object;
/** /**
* Set the name of the collection * Set the name of the collection
*
* @param string $collectionName
* @return AbstractCollectionStrategy
*/ */
public function setCollectionName(string $collectionName): AbstractCollectionStrategy public function setCollectionName(string $collectionName): AbstractCollectionStrategy
{ {
@ -62,8 +61,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Get the name of the collection * Get the name of the collection
*
* @return string
*/ */
public function getCollectionName(): string public function getCollectionName(): string
{ {
@ -72,9 +69,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Set the class metadata * Set the class metadata
*
* @param ClassMetadata $classMetadata
* @return AbstractCollectionStrategy
*/ */
public function setClassMetadata(ClassMetadata $classMetadata): AbstractCollectionStrategy public function setClassMetadata(ClassMetadata $classMetadata): AbstractCollectionStrategy
{ {
@ -84,8 +78,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Get the class metadata * Get the class metadata
*
* @return ClassMetadata
*/ */
public function getClassMetadata(): ClassMetadata public function getClassMetadata(): ClassMetadata
{ {
@ -95,16 +87,13 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Set the object * Set the object
* *
* @param object $object
*
* @return AbstractCollectionStrategy
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function setObject(object $object): AbstractCollectionStrategy public function setObject(object $object): AbstractCollectionStrategy
{ {
if (! is_object($object)) { if (! is_object($object)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf('The parameter given to setObject method of %s class is not an object', get_called_class()) sprintf('The parameter given to setObject method of %s class is not an object', static::class)
); );
} }
@ -114,8 +103,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Get the object * Get the object
*
* @return object
*/ */
public function getObject(): object public function getObject(): object
{ {
@ -133,9 +120,7 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Return the collection by value (using the public API) * Return the collection by value (using the public API)
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*
* @return Collection
*/ */
protected function getCollectionFromObjectByValue(): Collection protected function getCollectionFromObjectByValue(): Collection
{ {
@ -159,8 +144,7 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/** /**
* Return the collection by reference (not using the public API) * Return the collection by reference (not using the public API)
* *
* @return Collection * @throws ReflectionException
* @throws \ReflectionException
*/ */
protected function getCollectionFromObjectByReference(): Collection protected function getCollectionFromObjectByReference(): Collection
{ {
@ -173,15 +157,9 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
return $reflProperty->getValue($object); return $reflProperty->getValue($object);
} }
/** /**
* This method is used internally by array_udiff to check if two objects are equal, according to their * This method is used internally by array_udiff to check if two objects are equal, according to their
* SPL hash. This is needed because the native array_diff only compare strings * SPL hash. This is needed because the native array_diff only compare strings
*
* @param object $a
* @param object $b
*
* @return int
*/ */
protected function compareObjects(object $a, object $b): int protected function compareObjects(object $a, object $b): int
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,9 +18,14 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy; namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use ReflectionException;
use function array_udiff;
/** /**
* When this strategy is used for Collections, if the new collection does not contain elements that are present in * When this strategy is used for Collections, if the new collection does not contain elements that are present in
@ -29,16 +35,17 @@ use Doctrine\Common\Collections\Collection;
* *
* This strategy is by reference, this means it won't use public API to add/remove elements to the collection * This strategy is by reference, this means it won't use public API to add/remove elements to the collection
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
class AllowRemoveByReference extends AbstractCollectionStrategy class AllowRemoveByReference extends AbstractCollectionStrategy
{ {
/** /**
* {@inheritDoc} * {@inheritDoc}
* @throws \ReflectionException *
* @throws ReflectionException
*/ */
public function hydrate($value, $data = null): Collection public function hydrate($value, $data = null): Collection
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,11 +18,19 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy; namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use LogicException; use LogicException;
use Doctrine\Common\Collections\ArrayCollection;
use function array_udiff;
use function get_class;
use function method_exists;
use function sprintf;
use function ucfirst;
/** /**
* When this strategy is used for Collections, if the new collection does not contain elements that are present in * When this strategy is used for Collections, if the new collection does not contain elements that are present in
@ -31,10 +40,10 @@ use Doctrine\Common\Collections\ArrayCollection;
* *
* This strategy is by value, this means it will use the public API (in this case, adder and remover) * This strategy is by value, this means it will use the public API (in this case, adder and remover)
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
class AllowRemoveByValue extends AbstractCollectionStrategy class AllowRemoveByValue extends AbstractCollectionStrategy
{ {
@ -63,9 +72,9 @@ class AllowRemoveByValue extends AbstractCollectionStrategy
if ($collection instanceof Collection) { if ($collection instanceof Collection) {
$collection = $collection->toArray(); $collection = $collection->toArray();
/** @var array $collection */
} }
/** @var array $collection */
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects'])); $toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
$toRemove = new ArrayCollection(array_udiff($collection, $value, [$this, 'compareObjects'])); $toRemove = new ArrayCollection(array_udiff($collection, $value, [$this, 'compareObjects']));

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,8 +18,15 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy; namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\Collection;
use ReflectionException;
use function array_udiff;
/** /**
* When this strategy is used for Collections, if the new collection does not contain elements that are present in * When this strategy is used for Collections, if the new collection does not contain elements that are present in
* the original collection, then this strategy will not remove those elements. At most, it will add new elements. For * the original collection, then this strategy will not remove those elements. At most, it will add new elements. For
@ -27,18 +35,19 @@ namespace DoctrineMezzioModule\Hydrator\Strategy;
* *
* This strategy is by reference, this means it won't use the public API to remove elements * This strategy is by reference, this means it won't use the public API to remove elements
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
class DisallowRemoveByReference extends AbstractCollectionStrategy class DisallowRemoveByReference extends AbstractCollectionStrategy
{ {
/** /**
* {@inheritDoc} * {@inheritDoc}
* @throws \ReflectionException *
* @throws ReflectionException
*/ */
public function hydrate($value, $data = null) public function hydrate($value, $data = null): Collection
{ {
$collection = $this->getCollectionFromObjectByReference(); $collection = $this->getCollectionFromObjectByReference();
$collectionArray = $collection->toArray(); $collectionArray = $collection->toArray();

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,11 +18,19 @@
* <http://www.doctrine-project.org>. * <http://www.doctrine-project.org>.
*/ */
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy; namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use LogicException; use LogicException;
use Doctrine\Common\Collections\ArrayCollection;
use function array_udiff;
use function get_class;
use function method_exists;
use function sprintf;
use function ucfirst;
/** /**
* When this strategy is used for Collections, if the new collection does not contain elements that are present in * When this strategy is used for Collections, if the new collection does not contain elements that are present in
@ -31,10 +40,10 @@ use Doctrine\Common\Collections\ArrayCollection;
* *
* This strategy is by value, this means it will use the public API (in this case, remover) * This strategy is by value, this means it will use the public API (in this case, remover)
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0 * @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/ */
class DisallowRemoveByValue extends AbstractCollectionStrategy class DisallowRemoveByValue extends AbstractCollectionStrategy
{ {

View File

@ -1,26 +1,28 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator; namespace DoctrineMezzioModule\Validator;
use function is_object;
/** /**
* Class that validates if objects does not exist in a given repository with a given list of matched fields * Class that validates if objects does not exist in a given repository with a given list of matched fields
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.4.0 * @since 0.4.0
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
class NoObjectExists extends ObjectExists class NoObjectExists extends ObjectExists
{ {
/** /**
* Error constants * Error constants
*/ */
const ERROR_OBJECT_FOUND = 'objectFound'; public const ERROR_OBJECT_FOUND = 'objectFound';
/** /** @var array Message templates */
* @var array Message templates protected array $messageTemplates = [
*/
protected $messageTemplates = [
self::ERROR_OBJECT_FOUND => "An object matching '%value%' was found", self::ERROR_OBJECT_FOUND => "An object matching '%value%' was found",
]; ];

View File

@ -4,30 +4,38 @@ declare(strict_types=1);
namespace DoctrineMezzioModule\Validator; namespace DoctrineMezzioModule\Validator;
use Laminas\Validator\AbstractValidator;
use Laminas\Validator\Exception;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository;
use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\ArrayUtils;
use Laminas\Validator\AbstractValidator;
use Laminas\Validator\Exception;
use function array_combine;
use function array_key_exists;
use function array_values;
use function count;
use function get_class;
use function gettype;
use function is_object;
use function is_string;
use function sprintf;
/** /**
* Class that validates if objects exist in a given repository with a given list of matched fields * Class that validates if objects exist in a given repository with a given list of matched fields
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.4.0 * @since 0.4.0
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
class ObjectExists extends AbstractValidator class ObjectExists extends AbstractValidator
{ {
/** /**
* Error constants * Error constants
*/ */
const ERROR_NO_OBJECT_FOUND = 'noObjectFound'; public const ERROR_NO_OBJECT_FOUND = 'noObjectFound';
/** /** @var array Message templates */
* @var array Message templates protected array $messageTemplates = [
*/
protected $messageTemplates = [
self::ERROR_NO_OBJECT_FOUND => "No object matching '%value%' was found", self::ERROR_NO_OBJECT_FOUND => "No object matching '%value%' was found",
]; ];
@ -62,7 +70,7 @@ class ObjectExists extends AbstractValidator
if (is_object($options['object_repository'])) { if (is_object($options['object_repository'])) {
$provided = get_class($options['object_repository']); $provided = get_class($options['object_repository']);
} else { } else {
$provided = getType($options['object_repository']); $provided = gettype($options['object_repository']);
} }
} }
@ -144,7 +152,7 @@ class ObjectExists extends AbstractValidator
$matchedFieldsValues = @array_combine($this->fields, $value); $matchedFieldsValues = @array_combine($this->fields, $value);
/** @phan-suppress-next-line PhanTypeComparisonToArray */ /** @phan-suppress-next-line PhanTypeComparisonToArray */
if (false === $matchedFieldsValues) { // if (false === $matchedFieldsValues) {
throw new Exception\RuntimeException( throw new Exception\RuntimeException(
sprintf( sprintf(
'Provided values count is %s, while expected number of fields to be matched is %s', 'Provided values count is %s, while expected number of fields to be matched is %s',

View File

@ -1,38 +1,40 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service; namespace DoctrineMezzioModule\Validator\Service;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository;
use DoctrineMezzioModule\Validator\Service\Exception\ServiceCreationException;
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException; use Interop\Container\Exception\ContainerException;
use Laminas\ServiceManager\Factory\FactoryInterface; use Laminas\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\ServiceManager\ServiceLocatorInterface;
use DoctrineMezzioModule\Validator\Service\Exception\ServiceCreationException;
use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\ArrayUtils;
use function is_string;
use function sprintf;
/** /**
* Factory for creating NoObjectExists instances * Factory for creating NoObjectExists instances
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0 * @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
* @phan-file-suppress PhanTypeInvalidThrowsIsInterface * @phan-file-suppress PhanTypeInvalidThrowsIsInterface
*/ */
abstract class AbstractValidatorFactory implements FactoryInterface abstract class AbstractValidatorFactory implements FactoryInterface
{ {
const DEFAULT_OBJECTMANAGER_KEY = 'doctrine.entity_manager.orm_default'; public const DEFAULT_OBJECTMANAGER_KEY = 'doctrine.entity_manager.orm_default';
protected $creationOptions = []; protected array $creationOptions = [];
protected $validatorClass; protected string $validatorClass;
/** /**
* @param ContainerInterface $container
* @param array $options * @param array $options
* @return ObjectRepository
* @throws ServiceCreationException * @throws ServiceCreationException
*/ */
protected function getRepository(ContainerInterface $container, array $options): ObjectRepository protected function getRepository(ContainerInterface $container, array $options): ObjectRepository
@ -40,7 +42,7 @@ abstract class AbstractValidatorFactory implements FactoryInterface
if (empty($options['target_class'])) { if (empty($options['target_class'])) {
throw new ServiceCreationException(sprintf( throw new ServiceCreationException(sprintf(
"Option 'target_class' is missing when creating validator %s", "Option 'target_class' is missing when creating validator %s",
__CLASS__ self::class
)); ));
} }
@ -53,7 +55,6 @@ abstract class AbstractValidatorFactory implements FactoryInterface
} }
/** /**
* @param ContainerInterface $container
* @param array $options * @param array $options
* @return ObjectManager * @return ObjectManager
*/ */
@ -96,8 +97,6 @@ abstract class AbstractValidatorFactory implements FactoryInterface
} }
/** /**
* @param ServiceLocatorInterface $serviceLocator
* @return object
* @throws ContainerException * @throws ContainerException
*/ */
public function createService(ServiceLocatorInterface $serviceLocator): object public function createService(ServiceLocatorInterface $serviceLocator): object

View File

@ -1,15 +1,16 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service\Exception; namespace DoctrineMezzioModule\Validator\Service\Exception;
use RuntimeException as BaseRuntimeException; use RuntimeException as BaseRuntimeException;
/** /**
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0 * @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
*/ */
class ServiceCreationException extends BaseRuntimeException class ServiceCreationException extends BaseRuntimeException
{ {

View File

@ -1,24 +1,28 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service; namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\NoObjectExists; use DoctrineMezzioModule\Validator\NoObjectExists;
use Interop\Container\ContainerInterface;
/** /**
* Factory for creating NoObjectExists instances * Factory for creating NoObjectExists instances
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0 * @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
*/ */
class NoObjectExistsFactory extends AbstractValidatorFactory class NoObjectExistsFactory extends AbstractValidatorFactory
{ {
protected $validatorClass = NoObjectExists::class; protected string $validatorClass = NoObjectExists::class;
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): NoObjectExists /**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): NoObjectExists
{ {
$repository = $this->getRepository($container, $options); $repository = $this->getRepository($container, $options);

View File

@ -1,24 +1,28 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service; namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\ObjectExists; use DoctrineMezzioModule\Validator\ObjectExists;
use Interop\Container\ContainerInterface;
/** /**
* Factory for creating ObjectExists instances * Factory for creating ObjectExists instances
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0 * @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
*/ */
class ObjectExistsFactory extends AbstractValidatorFactory class ObjectExistsFactory extends AbstractValidatorFactory
{ {
protected $validatorClass = ObjectExists::class; protected string $validatorClass = ObjectExists::class;
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ObjectExists /**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): ObjectExists
{ {
$repository = $this->getRepository($container, $options); $repository = $this->getRepository($container, $options);

View File

@ -1,18 +1,22 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service; namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\UniqueObject; use DoctrineMezzioModule\Validator\UniqueObject;
use Interop\Container\ContainerInterface;
class UniqueObjectFactory extends AbstractValidatorFactory class UniqueObjectFactory extends AbstractValidatorFactory
{ {
protected $validatorClass = UniqueObject::class; protected string $validatorClass = UniqueObject::class;
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): UniqueObject /**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): UniqueObject
{ {
$useContext = isset($options['use_context']) ? (boolean) $options['use_context'] : false; $useContext = isset($options['use_context']) ? (bool) $options['use_context'] : false;
return new UniqueObject($this->merge($options, [ return new UniqueObject($this->merge($options, [
'object_manager' => $this->getObjectManager($container, $options), 'object_manager' => $this->getObjectManager($container, $options),

View File

@ -1,40 +1,41 @@
<?php <?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator; namespace DoctrineMezzioModule\Validator;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Laminas\Validator\Exception; use Laminas\Validator\Exception;
use function array_diff_assoc;
use function array_key_exists;
use function count;
use function get_class;
use function gettype;
use function is_object;
use function sprintf;
/** /**
* Class that validates if objects exist in a given repository with a given list of matched fields only once. * Class that validates if objects exist in a given repository with a given list of matched fields only once.
* *
* @license MIT
* @link http://www.doctrine-project.org/ * @link http://www.doctrine-project.org/
* @author Oskar Bley <oskar@programming-php.net> * @license MIT
*/ */
class UniqueObject extends ObjectExists class UniqueObject extends ObjectExists
{ {
/** /**
* Error constants * Error constants
*/ */
const ERROR_OBJECT_NOT_UNIQUE = 'objectNotUnique'; public const ERROR_OBJECT_NOT_UNIQUE = 'objectNotUnique';
/** /** @var array Message templates */
* @var array Message templates protected array $messageTemplates = [
*/
protected $messageTemplates = [
self::ERROR_OBJECT_NOT_UNIQUE => "There is already another object matching '%value%'", self::ERROR_OBJECT_NOT_UNIQUE => "There is already another object matching '%value%'",
]; ];
/** protected ObjectManager $objectManager;
* @var ObjectManager
*/
protected $objectManager;
/** protected bool $useContext;
* @var boolean
*/
protected $useContext;
/*** /***
* Constructor * Constructor
@ -57,7 +58,7 @@ class UniqueObject extends ObjectExists
if (is_object($options['object_manager'])) { if (is_object($options['object_manager'])) {
$provided = get_class($options['object_manager']); $provided = get_class($options['object_manager']);
} else { } else {
$provided = getType($options['object_manager']); $provided = gettype($options['object_manager']);
} }
} }
@ -71,7 +72,7 @@ class UniqueObject extends ObjectExists
} }
$this->objectManager = $options['object_manager']; $this->objectManager = $options['object_manager'];
$this->useContext = isset($options['use_context']) ? (boolean) $options['use_context'] : false; $this->useContext = isset($options['use_context']) ? (bool) $options['use_context'] : false;
} }
/** /**
@ -79,7 +80,6 @@ class UniqueObject extends ObjectExists
* *
* @param mixed $value * @param mixed $value
* @param array $context * @param array $context
* @return boolean
*/ */
public function isValid($value, $context = null): bool public function isValid($value, $context = null): bool
{ {
@ -97,7 +97,7 @@ class UniqueObject extends ObjectExists
$expectedIdentifiers = $this->getExpectedIdentifiers($context); $expectedIdentifiers = $this->getExpectedIdentifiers($context);
$foundIdentifiers = $this->getFoundIdentifiers($match); $foundIdentifiers = $this->getFoundIdentifiers($match);
if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) == 0) { if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) === 0) {
return true; return true;
} }
@ -108,11 +108,10 @@ class UniqueObject extends ObjectExists
/** /**
* Gets the identifiers from the matched object. * Gets the identifiers from the matched object.
* *
* @param object $match
* @return array * @return array
* @throws Exception\RuntimeException * @throws Exception\RuntimeException
*/ */
protected function getFoundIdentifiers($match) protected function getFoundIdentifiers(object $match): array
{ {
return $this->objectManager return $this->objectManager
->getClassMetadata($this->objectRepository->getClassName()) ->getClassMetadata($this->objectRepository->getClassName())
@ -126,7 +125,7 @@ class UniqueObject extends ObjectExists
* @return array * @return array
* @throws Exception\RuntimeException * @throws Exception\RuntimeException
*/ */
protected function getExpectedIdentifiers($context = null) protected function getExpectedIdentifiers($context = null): array
{ {
if ($context === null) { if ($context === null) {
throw new Exception\RuntimeException( throw new Exception\RuntimeException(
@ -145,7 +144,7 @@ class UniqueObject extends ObjectExists
$result = []; $result = [];
foreach ($this->getIdentifiers() as $identifierField) { foreach ($this->getIdentifiers() as $identifierField) {
if (! array_key_exists($identifierField, $context)) { if (! array_key_exists($identifierField, $context)) {
throw new Exception\RuntimeException(\sprintf('Expected context to contain %s', $identifierField)); throw new Exception\RuntimeException(sprintf('Expected context to contain %s', $identifierField));
} }
$result[$identifierField] = $context[$identifierField]; $result[$identifierField] = $context[$identifierField];
@ -153,11 +152,10 @@ class UniqueObject extends ObjectExists
return $result; return $result;
} }
/** /**
* @return array the names of the identifiers * @return array the names of the identifiers
*/ */
protected function getIdentifiers() protected function getIdentifiers(): array
{ {
return $this->objectManager return $this->objectManager
->getClassMetadata($this->objectRepository->getClassName()) ->getClassMetadata($this->objectRepository->getClassName())