* 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
/vendor/
/.phpcs-cache

View File

@ -25,11 +25,15 @@
}
],
"require-dev": {
"phan/phan": "^4.0"
"phan/phan": "^4.0",
"squizlabs/php_codesniffer": "^3.5.8",
"laminas/laminas-coding-standard": "^2.1.4"
},
"scripts": {
"phan": "phan",
"phan-init": "phan --init"
"phan-init": "phan --init",
"cs-check": "phpcs",
"cs-fix": "phpcbf"
},
"extra": {
"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",
"This file is @generated automatically"
],
"content-hash": "25e1f2c374a9f4e31b1efbaf7c8e5115",
"content-hash": "2ddfae5af0f6b6f4051f0c284930eaa5",
"packages": [
{
"name": "composer/package-versions-deprecated",
@ -117,16 +117,16 @@
},
{
"name": "doctrine/annotations",
"version": "1.11.1",
"version": "1.12.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/annotations.git",
"reference": "ce77a7ba1770462cd705a91a151b6c3746f9c6ad"
"reference": "ebec9b1708c95d7602245c8172773f6b4e0c3be1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/ce77a7ba1770462cd705a91a151b6c3746f9c6ad",
"reference": "ce77a7ba1770462cd705a91a151b6c3746f9c6ad",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/ebec9b1708c95d7602245c8172773f6b4e0c3be1",
"reference": "ebec9b1708c95d7602245c8172773f6b4e0c3be1",
"shasum": ""
},
"require": {
@ -141,11 +141,6 @@
"phpunit/phpunit": "^7.5 || ^9.1.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.11.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations"
@ -186,9 +181,9 @@
],
"support": {
"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",
@ -1289,16 +1284,16 @@
},
{
"name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.2",
"version": "v1.0.3",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/proxy-manager-lts.git",
"reference": "4a66e4e0d3279d3bb3722963b4294331fabe15bc"
"reference": "121af47c9aee9c03031bdeca3fac0540f59aa5c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/4a66e4e0d3279d3bb3722963b4294331fabe15bc",
"reference": "4a66e4e0d3279d3bb3722963b4294331fabe15bc",
"url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/121af47c9aee9c03031bdeca3fac0540f59aa5c3",
"reference": "121af47c9aee9c03031bdeca3fac0540f59aa5c3",
"shasum": ""
},
"require": {
@ -1355,7 +1350,7 @@
],
"support": {
"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": [
{
@ -1367,7 +1362,7 @@
"type": "tidelift"
}
],
"time": "2021-01-04T11:21:26+00:00"
"time": "2021-01-14T21:52:44+00:00"
},
{
"name": "laminas/laminas-code",
@ -1836,16 +1831,16 @@
},
{
"name": "laminas/laminas-servicemanager",
"version": "3.6.0",
"version": "3.6.4",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-servicemanager.git",
"reference": "0c1ec25ff486d690c8aa8aeb93f560dab593aa78"
"reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/0c1ec25ff486d690c8aa8aeb93f560dab593aa78",
"reference": "0c1ec25ff486d690c8aa8aeb93f560dab593aa78",
"url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/b1445e1a7077c21b0fad0974a1b7a11b9dbe0828",
"reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828",
"shasum": ""
},
"require": {
@ -1919,7 +1914,7 @@
"type": "community_bridge"
}
],
"time": "2021-01-10T15:50:33+00:00"
"time": "2021-02-03T08:44:41+00:00"
},
{
"name": "laminas/laminas-stdlib",
@ -1981,16 +1976,16 @@
},
{
"name": "laminas/laminas-validator",
"version": "2.14.0",
"version": "2.14.4",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-validator.git",
"reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e"
"reference": "e370c4695db1c81e6dfad38d8c4dbdb37b23d776"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-validator/zipball/8da5e20ed7b2b8101c1de68ca8dc0180210ed23e",
"reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e",
"url": "https://api.github.com/repos/laminas/laminas-validator/zipball/e370c4695db1c81e6dfad38d8c4dbdb37b23d776",
"reference": "e370c4695db1c81e6dfad38d8c4dbdb37b23d776",
"shasum": ""
},
"require": {
@ -2069,7 +2064,7 @@
"type": "community_bridge"
}
],
"time": "2021-01-07T16:07:31+00:00"
"time": "2021-01-24T20:45:49+00:00"
},
{
"name": "laminas/laminas-zendframework-bridge",
@ -2246,16 +2241,16 @@
},
{
"name": "symfony/console",
"version": "v5.2.1",
"version": "v5.2.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "47c02526c532fb381374dab26df05e7313978976"
"reference": "89d4b176d12a2946a1ae4e34906a025b7b6b135a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/47c02526c532fb381374dab26df05e7313978976",
"reference": "47c02526c532fb381374dab26df05e7313978976",
"url": "https://api.github.com/repos/symfony/console/zipball/89d4b176d12a2946a1ae4e34906a025b7b6b135a",
"reference": "89d4b176d12a2946a1ae4e34906a025b7b6b135a",
"shasum": ""
},
"require": {
@ -2314,7 +2309,7 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Console Component",
"description": "Eases the creation of beautiful and testable command line interfaces",
"homepage": "https://symfony.com",
"keywords": [
"cli",
@ -2323,7 +2318,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v5.2.1"
"source": "https://github.com/symfony/console/tree/v5.2.3"
},
"funding": [
{
@ -2339,20 +2334,20 @@
"type": "tidelift"
}
],
"time": "2020-12-18T08:03:05+00:00"
"time": "2021-01-28T22:06:19+00:00"
},
{
"name": "symfony/filesystem",
"version": "v5.2.1",
"version": "v5.2.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "fa8f8cab6b65e2d99a118e082935344c5ba8c60d"
"reference": "262d033b57c73e8b59cd6e68a45c528318b15038"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/fa8f8cab6b65e2d99a118e082935344c5ba8c60d",
"reference": "fa8f8cab6b65e2d99a118e082935344c5ba8c60d",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/262d033b57c73e8b59cd6e68a45c528318b15038",
"reference": "262d033b57c73e8b59cd6e68a45c528318b15038",
"shasum": ""
},
"require": {
@ -2382,10 +2377,10 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Filesystem Component",
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v5.2.1"
"source": "https://github.com/symfony/filesystem/tree/v5.2.3"
},
"funding": [
{
@ -2401,11 +2396,11 @@
"type": "tidelift"
}
],
"time": "2020-11-30T17:05:38+00:00"
"time": "2021-01-27T10:01:46+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
@ -2464,7 +2459,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1"
},
"funding": [
{
@ -2484,16 +2479,16 @@
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "267a9adeb8ecb8071040a740930e077cdfb987af"
"reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/267a9adeb8ecb8071040a740930e077cdfb987af",
"reference": "267a9adeb8ecb8071040a740930e077cdfb987af",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/5601e09b69f26c1828b13b6bb87cb07cddba3170",
"reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170",
"shasum": ""
},
"require": {
@ -2545,7 +2540,7 @@
"shim"
],
"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": [
{
@ -2561,20 +2556,20 @@
"type": "tidelift"
}
],
"time": "2021-01-07T16:49:33+00:00"
"time": "2021-01-22T09:19:47+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "6e971c891537eb617a00bb07a43d182a6915faba"
"reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/6e971c891537eb617a00bb07a43d182a6915faba",
"reference": "6e971c891537eb617a00bb07a43d182a6915faba",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/43a0283138253ed1d48d352ab6d0bdb3f809f248",
"reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248",
"shasum": ""
},
"require": {
@ -2629,7 +2624,7 @@
"shim"
],
"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": [
{
@ -2645,20 +2640,20 @@
"type": "tidelift"
}
],
"time": "2021-01-07T17:09:11+00:00"
"time": "2021-01-22T09:19:47+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13"
"reference": "5232de97ee3b75b0360528dae24e73db49566ab1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f377a3dd1fde44d37b9831d68dc8dea3ffd28e13",
"reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1",
"reference": "5232de97ee3b75b0360528dae24e73db49566ab1",
"shasum": ""
},
"require": {
@ -2709,7 +2704,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.0"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.1"
},
"funding": [
{
@ -2725,11 +2720,11 @@
"type": "tidelift"
}
],
"time": "2021-01-07T16:49:33+00:00"
"time": "2021-01-22T09:19:47+00:00"
},
{
"name": "symfony/polyfill-php73",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
@ -2788,7 +2783,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.22.0"
"source": "https://github.com/symfony/polyfill-php73/tree/v1.22.1"
},
"funding": [
{
@ -2808,7 +2803,7 @@
},
{
"name": "symfony/polyfill-php80",
"version": "v1.22.0",
"version": "v1.22.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
@ -2871,7 +2866,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.22.0"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1"
},
"funding": [
{
@ -2970,16 +2965,16 @@
},
{
"name": "symfony/stopwatch",
"version": "v5.2.1",
"version": "v5.2.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "2b105c0354f39a63038a1d8bf776ee92852813af"
"reference": "b12274acfab9d9850c52583d136a24398cdf1a0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/2b105c0354f39a63038a1d8bf776ee92852813af",
"reference": "2b105c0354f39a63038a1d8bf776ee92852813af",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/b12274acfab9d9850c52583d136a24398cdf1a0c",
"reference": "b12274acfab9d9850c52583d136a24398cdf1a0c",
"shasum": ""
},
"require": {
@ -3009,10 +3004,10 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Stopwatch Component",
"description": "Provides a way to profile code",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/stopwatch/tree/v5.2.1"
"source": "https://github.com/symfony/stopwatch/tree/v5.2.3"
},
"funding": [
{
@ -3028,20 +3023,20 @@
"type": "tidelift"
}
],
"time": "2020-11-01T16:14:45+00:00"
"time": "2021-01-27T10:15:41+00:00"
},
{
"name": "symfony/string",
"version": "v5.2.1",
"version": "v5.2.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed"
"reference": "c95468897f408dd0aca2ff582074423dd0455122"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed",
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed",
"url": "https://api.github.com/repos/symfony/string/zipball/c95468897f408dd0aca2ff582074423dd0455122",
"reference": "c95468897f408dd0aca2ff582074423dd0455122",
"shasum": ""
},
"require": {
@ -3084,7 +3079,7 @@
"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",
"keywords": [
"grapheme",
@ -3095,7 +3090,7 @@
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v5.2.1"
"source": "https://github.com/symfony/string/tree/v5.2.3"
},
"funding": [
{
@ -3111,7 +3106,7 @@
"type": "tidelift"
}
],
"time": "2020-12-05T07:33:16+00:00"
"time": "2021-01-25T15:14:59+00:00"
}
],
"packages-dev": [
@ -3260,26 +3255,96 @@
"time": "2020-11-13T08:04:11+00:00"
},
{
"name": "felixfbecker/advanced-json-rpc",
"version": "v3.1.2",
"name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v0.7.1",
"source": {
"type": "git",
"url": "https://github.com/felixfbecker/php-advanced-json-rpc.git",
"reference": "804ee564f1c7f0bc160d755fc5bdd17a04545070"
"url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
"reference": "fe390591e0241955f22eb9ba327d137e501c771c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/804ee564f1c7f0bc160d755fc5bdd17a04545070",
"reference": "804ee564f1c7f0bc160d755fc5bdd17a04545070",
"url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c",
"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": ""
},
"require": {
"netresearch/jsonmapper": "^1.0 || ^2.0",
"php": ">=7.0",
"php": "^7.1 || ^8.0",
"phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0.0"
"phpunit/phpunit": "^7.0 || ^8.0"
},
"type": "library",
"autoload": {
@ -3300,9 +3365,63 @@
"description": "A more advanced JSONRPC implementation",
"support": {
"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",
@ -3402,16 +3521,16 @@
},
{
"name": "phan/phan",
"version": "4.0.2",
"version": "4.0.3",
"source": {
"type": "git",
"url": "https://github.com/phan/phan.git",
"reference": "2e5f16a17aa909c91397c6fbba0309b4fef0df53"
"reference": "95171b8a89ff2433e7ebc27d8a133743f7d78d3b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phan/phan/zipball/2e5f16a17aa909c91397c6fbba0309b4fef0df53",
"reference": "2e5f16a17aa909c91397c6fbba0309b4fef0df53",
"url": "https://api.github.com/repos/phan/phan/zipball/95171b8a89ff2433e7ebc27d8a133743f7d78d3b",
"reference": "95171b8a89ff2433e7ebc27d8a133743f7d78d3b",
"shasum": ""
},
"require": {
@ -3473,9 +3592,9 @@
],
"support": {
"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",
@ -3635,6 +3754,59 @@
},
"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",
"version": "1.1.3",
@ -3751,17 +3923,189 @@
},
"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",
"version": "1.9.1",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
"url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": ""
},
@ -3799,8 +4143,8 @@
"validate"
],
"support": {
"issues": "https://github.com/webmozart/assert/issues",
"source": "https://github.com/webmozart/assert/tree/master"
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.9.1"
},
"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,12 +20,11 @@ class ConfigProvider
*
* To add a bit of a structure, each section is defined in a separate
* method which returns an array with its configuration.
*
*/
public function __invoke() : array
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'dependencies' => $this->getDependencies(),
'form_elements' => $this->getFormElements(),
];
}
@ -33,12 +32,12 @@ class ConfigProvider
/**
* Returns the container dependencies
*/
public function getDependencies() : array
public function getDependencies(): array
{
return [
'aliases' => [
'EventManager' => EventManager::class,
'doctrine.hydrator' => Hydrator\DoctrineObject::class,
'aliases' => [
'EventManager' => EventManager::class,
'doctrine.hydrator' => Hydrator\DoctrineObject::class,
'doctrine.entity_manager.orm_default' => EntityManager::class,
],
'invokables' => [
@ -46,7 +45,7 @@ class ConfigProvider
],
'factories' => [
Hydrator\DoctrineObject::class => Hydrator\DoctrineObjectFactory::class,
EntityManager::class => EntityManagerFactory::class,
EntityManager::class => EntityManagerFactory::class,
],
];
}
@ -54,13 +53,13 @@ class ConfigProvider
/**
* Returns the form dependencies
*/
public function getFormElements() : array
public function getFormElements(): array
{
return [
'aliases' => [
'aliases' => [
'doctrine.object_select' => Form\Element\ObjectSelect::class,
],
'factories' => [
'factories' => [
Form\Element\ObjectSelect::class => Form\Element\ElementFactory::class,
],
];

View File

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

View File

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

View File

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

View File

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

View File

@ -1,87 +1,75 @@
<?php
declare(strict_types=1);
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\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
{
use ArrayOrTraversableGuardTrait;
/**
* @var array|Traversable
*/
/** @var array|Traversable */
protected $objects;
/**
* @var string
*/
protected $targetClass;
protected string $targetClass;
/**
* @var array
*/
protected $valueOptions = [];
/** @var array */
protected array $valueOptions = [];
/**
* @var array
*/
protected $findMethod = [];
/** @var array */
protected array $findMethod = [];
/**
* @var string
*/
protected $property;
protected string $property;
/**
* @var array
*/
protected $option_attributes = [];
/** @var array */
protected array $optionAttributes = [];
/**
* @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;
/**
* @var bool|null
*/
protected $isMethod;
protected ?bool $isMethod;
/**
* @var ObjectManager
*/
protected $objectManager;
protected ObjectManager $objectManager;
/**
* @var bool
*/
protected $displayEmptyItem = false;
protected bool $displayEmptyItem = false;
/**
* @var string
*/
protected $emptyItemLabel = '';
protected string $emptyItemLabel = '';
/**
* @var string|null
*/
protected $optgroupIdentifier;
protected ?string $optgroupIdentifier;
/**
* @var string|null
*/
protected $optgroupDefault;
protected ?string $optgroupDefault;
public function setOptions($options)
public function setOptions(array $options)
{
if (isset($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)) {
$this->loadValueOptions();
@ -139,6 +130,7 @@ class Proxy
/**
* @return array|Traversable
* @throws ReflectionException
*/
public function getObjects()
{
@ -149,21 +141,14 @@ class Proxy
/**
* 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;
return $this;
}
/**
* @return string
*/
public function getEmptyItemLabel(): string
{
return $this->emptyItemLabel;
@ -174,23 +159,19 @@ class Proxy
*/
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
*
* @param boolean $displayEmptyItem
*
* @return Proxy
*/
public function setDisplayEmptyItem(bool $displayEmptyItem): Proxy
{
@ -199,9 +180,6 @@ class Proxy
return $this;
}
/**
* @return boolean
*/
public function getDisplayEmptyItem(): bool
{
return $this->displayEmptyItem;
@ -209,10 +187,6 @@ class Proxy
/**
* Set the object manager
*
* @param ObjectManager $objectManager
*
* @return Proxy
*/
public function setObjectManager(ObjectManager $objectManager): Proxy
{
@ -223,8 +197,6 @@ class Proxy
/**
* Get the object manager
*
* @return ObjectManager
*/
public function getObjectManager(): ObjectManager
{
@ -233,10 +205,6 @@ class Proxy
/**
* Set the FQCN of the target object
*
* @param string $targetClass
*
* @return Proxy
*/
public function setTargetClass(string $targetClass): Proxy
{
@ -247,8 +215,6 @@ class Proxy
/**
* Get the target class
*
* @return string
*/
public function getTargetClass(): string
{
@ -257,10 +223,6 @@ class Proxy
/**
* Set the property to use as the label in the options
*
* @param string $property
*
* @return Proxy
*/
public function setProperty(string $property): Proxy
{
@ -269,9 +231,6 @@ class Proxy
return $this;
}
/**
* @return string
*/
public function getProperty(): string
{
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
*
* @param callable $callable A callable used to create a label based off of an Entity
*
* @return void
* @throws InvalidArgumentException
*/
@ -296,41 +254,26 @@ class Proxy
$this->labelGenerator = $callable;
}
/**
* @return callable|null
*/
public function getLabelGenerator(): ?callable
{
return $this->labelGenerator;
}
/**
* @return string|null
*/
public function getOptgroupIdentifier(): ?string
{
return $this->optgroupIdentifier;
}
/**
* @param string $optgroupIdentifier
*/
public function setOptgroupIdentifier(string $optgroupIdentifier)
{
$this->optgroupIdentifier = (string) $optgroupIdentifier;
}
/**
* @return string|null
*/
public function getOptgroupDefault(): ?string
{
return $this->optgroupDefault;
}
/**
* @param string $optgroupDefault
*/
public function setOptgroupDefault(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
*
* @param boolean $method
*
* @return 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
*
* @param array $findMethod
*
* @return Proxy
*/
public function setFindMethod(array $findMethod): Proxy
{
@ -382,9 +319,7 @@ class Proxy
}
/**
* @param $targetEntity
*
* @return string|null
* @param Entity $targetEntity
*/
protected function generateLabel($targetEntity): ?string
{
@ -396,8 +331,7 @@ class Proxy
}
/**
* @param $value
*
* @param Collection|Entity $value
* @return array|mixed|object
* @throws RuntimeException
*/
@ -429,7 +363,7 @@ class Proxy
// TODO: handle composite (multiple) identifiers
if (null !== $identifier && count($identifier) > 1) {
//$value = $key;
throw new CompositeIdentifierException("Can't handle composite identifiers");
} else {
$value = current($metadata->getIdentifierValues($value));
}
@ -443,10 +377,10 @@ class Proxy
* Load objects
*
* @return void
* @throws Exception\InvalidRepositoryResultException
* @throws InvalidRepositoryResultException
* @throws ReflectionException
* @throws RuntimeException
* @throws \Exception
* @throws Exception
*/
protected function loadObjects()
{
@ -513,8 +447,8 @@ class Proxy
/**
* Load value options
*
* @throws RuntimeException
* @return void
* @throws RuntimeException|ReflectionException
*/
protected function loadValueOptions()
{
@ -540,7 +474,7 @@ class Proxy
if (null !== ($generatedLabel = $this->generateLabel($object))) {
$label = $generatedLabel;
} elseif ($property = $this->property) {
if ($this->isMethod == false && ! $metadata->hasField($property)) {
if ($this->isMethod === false && ! $metadata->hasField($property)) {
throw new RuntimeException(
sprintf(
'Property "%s" could not be found in object "%s"',
@ -551,7 +485,7 @@ class Proxy
}
$inflector = InflectorFactory::create()->build();
$getter = 'get' . $inflector->classify($property);
$getter = 'get' . $inflector->classify($property);
if (! is_callable([$object, $getter])) {
throw new RuntimeException(
@ -604,15 +538,16 @@ class Proxy
}
// 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];
continue;
}
// optgroup_identifier found, handle grouping
$inflector = InflectorFactory::create()->build();
$optgroupGetter = 'get' . $inflector->classify($this->getOptgroupIdentifier());
$inflector = InflectorFactory::create()->build();
$optgroupGetter = 'get' . $inflector->classify($optGroupId);
if (! is_callable([$object, $optgroupGetter])) {
throw new RuntimeException(
@ -623,7 +558,7 @@ class Proxy
$optgroup = $object->{$optgroupGetter}();
// 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]['options'][] = [
'label' => $label,
@ -637,7 +572,7 @@ class Proxy
$optgroupDefault = $this->getOptgroupDefault();
// 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];
continue;

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,21 +18,46 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator;
use DateTime;
use DateTimeImmutable;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Exception;
use InvalidArgumentException;
use Laminas\Hydrator\AbstractHydrator;
use Laminas\Hydrator\Filter\FilterProviderInterface;
use Laminas\Stdlib\ArrayUtils;
use ReflectionException;
use RuntimeException;
use Traversable;
use Laminas\Stdlib\ArrayUtils;
use Laminas\Hydrator\AbstractHydrator;
use Laminas\Hydrator\Filter\FilterProviderInterface;
use function array_filter;
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
@ -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
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
class DoctrineObject extends AbstractHydrator
{
/**
* @var ObjectManager
*/
protected ObjectManager $objectManager;
/**
* @var ClassMetadata
*/
protected ClassMetadata $metadata;
/**
* @var bool
*/
protected bool $byValue = true;
/**
* Constructor
*
@ -77,7 +93,6 @@ class DoctrineObject extends AbstractHydrator
/**
* Extract values from an object
*
* @param object $object
* @return array
* @throws ReflectionException
*/
@ -96,8 +111,6 @@ class DoctrineObject extends AbstractHydrator
* Hydrate $object with the provided $data.
*
* @param array $data
* @param object $object
* @return object
* @throws ReflectionException
* @throws Exception
*/
@ -115,7 +128,6 @@ class DoctrineObject extends AbstractHydrator
/**
* Prepare the hydrator by adding strategies to every collection valued associations
*
* @param object $object
* @return void
*/
protected function prepare(object $object)
@ -137,7 +149,7 @@ class DoctrineObject extends AbstractHydrator
foreach ($associations as $association) {
if ($this->metadata->isCollectionValuedAssociation($association)) {
// Add a strategy if the association has none set by user
if (!$this->hasStrategy($association)) {
if (! $this->hasStrategy($association)) {
if ($this->byValue) {
$this->addStrategy($association, new Strategy\AllowRemoveByValue());
} else {
@ -147,7 +159,7 @@ class DoctrineObject extends AbstractHydrator
$strategy = $this->getStrategy($association);
if (!$strategy instanceof Strategy\AbstractCollectionStrategy) {
if (! $strategy instanceof Strategy\AbstractCollectionStrategy) {
throw new InvalidArgumentException(
sprintf(
'Strategies used for collections valued associations must inherit from '
@ -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
* API, in this case, getters)
*
* @param object $object
* @return array
* @throws RuntimeException
*/
@ -181,22 +192,24 @@ class DoctrineObject extends AbstractHydrator
$data = [];
foreach ($fieldNames as $fieldName) {
if ($filter && !$filter->filter($fieldName)) {
if ($filter && ! $filter->filter($fieldName)) {
continue;
}
$inflector = InflectorFactory::create()->build();
$getter = 'get' . $inflector->classify($fieldName);
$isser = 'is' . $inflector->classify($fieldName);
$getter = 'get' . $inflector->classify($fieldName);
$isser = 'is' . $inflector->classify($fieldName);
$dataFieldName = $this->computeExtractFieldName($fieldName);
if (in_array($getter, $methods)) {
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$getter(), $object);
} elseif (in_array($isser, $methods)) {
$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))
&& in_array($fieldName, $methods)) {
&& in_array($fieldName, $methods)
) {
$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
* directly fetched without using the public API of the entity, in this case, getters)
*
* @param object $object
* @return array
* @throws ReflectionException
*/
@ -224,7 +236,7 @@ class DoctrineObject extends AbstractHydrator
$data = [];
foreach ($fieldNames as $fieldName) {
if ($filter && !$filter->filter($fieldName)) {
if ($filter && ! $filter->filter($fieldName)) {
continue;
}
$reflProperty = $refl->getProperty($fieldName);
@ -242,8 +254,6 @@ class DoctrineObject extends AbstractHydrator
* case, setters)
*
* @param array $data
* @param object $object
* @return object
* @throws RuntimeException|ReflectionException
* @throws Exception
*/
@ -257,10 +267,10 @@ class DoctrineObject extends AbstractHydrator
}
foreach ($data as $field => $value) {
$field = $this->computeHydrateFieldName($field);
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
$field = $this->computeHydrateFieldName($field);
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
$inflector = InflectorFactory::create()->build();
$setter = 'set' . $inflector->classify($field);
$setter = 'set' . $inflector->classify($field);
if ($metadata->hasAssociation($field)) {
$target = $metadata->getAssociationTargetClass($field);
@ -272,8 +282,9 @@ class DoctrineObject extends AbstractHydrator
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
if (null === $value
&& !current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
if (
null === $value
&& ! current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
) {
continue;
}
@ -300,8 +311,6 @@ class DoctrineObject extends AbstractHydrator
* setters)
*
* @param array $data
* @param object $object
* @return object
* @throws Exception
*/
protected function hydrateByReference(array $data, object $object): object
@ -318,7 +327,7 @@ class DoctrineObject extends AbstractHydrator
$field = $this->computeHydrateFieldName($field);
// Ignore unknown fields
if (!$refl->hasProperty($field)) {
if (! $refl->hasProperty($field)) {
continue;
}
@ -349,8 +358,6 @@ class DoctrineObject extends AbstractHydrator
* tricks like setting manually the existing id directly into the entity
*
* @param array $data The data that may contain identifiers keys
* @param object $object
* @return object
*/
protected function tryConvertArrayToObject(array $data, object $object): ?object
{
@ -363,7 +370,7 @@ class DoctrineObject extends AbstractHydrator
}
foreach ($identifierNames as $identifierName) {
if (!isset($data[$identifierName])) {
if (! isset($data[$identifierName])) {
return $object;
}
@ -381,22 +388,20 @@ class DoctrineObject extends AbstractHydrator
* and a target instance will be initialized and then hydrated. The hydrated
* target will be returned.
*
* @param string $target
* @param mixed $value
* @return object
* @throws ReflectionException
*/
protected function toOne(string $target, $value): ?object
{
$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
$identifiers = array_intersect_key(
$value,
array_flip($metadata->getIdentifier())
);
$object = $this->find($identifiers, $target) ?: new $target;
$object = $this->find($identifiers, $target) ?: new $target();
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
* changing the collection of the object
*
* @param object $object
* @param mixed $collectionName
* @param string $target
* @param mixed $values
*
* @return void
* @throws InvalidArgumentException|ReflectionException
*/
@ -422,8 +424,8 @@ class DoctrineObject extends AbstractHydrator
$metadata = $this->objectManager->getClassMetadata(ltrim($target, '\\'));
$identifier = $metadata->getIdentifier();
if (!is_array($values) && !$values instanceof Traversable) {
$values = (array)$values;
if (! is_array($values) && ! $values instanceof Traversable) {
$values = (array) $values;
}
$collection = [];
@ -453,7 +455,7 @@ class DoctrineObject extends AbstractHydrator
}
break;
case 'array':
if (array_key_exists($field, $value) && $value[$field] != null) {
if (array_key_exists($field, $value) && $value[$field] !== null) {
$find[$field] = $value[$field];
unset($value[$field]); // removed identifier from persistable data
}
@ -465,10 +467,10 @@ class DoctrineObject extends AbstractHydrator
}
}
if (!empty($find) && $found = $this->find($find, $target)) {
$collection[] = (is_array($value)) ? $this->hydrate($value, $found) : $found;
if (! empty($find) && $found = $this->find($find, $target)) {
$collection[] = is_array($value) ? $this->hydrate($value, $found) : $found;
} 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)
*
* @param mixed $value
* @param string $typeOfField
* @return DateTime|DateTimeImmutable|null
* @throws Exception
*/
@ -545,9 +546,6 @@ class DoctrineObject extends AbstractHydrator
* Find an object by a given target class and identifier
*
* @param mixed $identifiers
* @param string $targetClass
*
* @return object|null
*/
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
*
* @param mixed $identifier
*
* @return bool
*/
private function isNullIdentifier($identifier): bool
{
@ -591,10 +587,6 @@ class DoctrineObject extends AbstractHydrator
/**
* Applies the naming strategy if there is one set
*
* @param string $field
*
* @return string
*/
protected function computeHydrateFieldName(string $field): string
{
@ -606,10 +598,6 @@ class DoctrineObject extends AbstractHydrator
/**
* Applies the naming strategy if there is one set
*
* @param string $field
*
* @return string
*/
protected function computeExtractFieldName(string $field): string
{

View File

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

View File

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

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,42 +18,40 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy;
use InvalidArgumentException;
use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\Mapping\ClassMetadata;
use InvalidArgumentException;
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/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
abstract class AbstractCollectionStrategy implements StrategyInterface
{
/**
* @var string
*/
protected $collectionName;
protected string $collectionName;
/**
* @var ClassMetadata
*/
protected $metadata;
/**
* @var object
*/
protected $object;
protected ClassMetadata $metadata;
protected object $object;
/**
* Set the name of the collection
*
* @param string $collectionName
* @return AbstractCollectionStrategy
*/
public function setCollectionName(string $collectionName): AbstractCollectionStrategy
{
@ -62,8 +61,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Get the name of the collection
*
* @return string
*/
public function getCollectionName(): string
{
@ -72,9 +69,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Set the class metadata
*
* @param ClassMetadata $classMetadata
* @return AbstractCollectionStrategy
*/
public function setClassMetadata(ClassMetadata $classMetadata): AbstractCollectionStrategy
{
@ -84,8 +78,6 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Get the class metadata
*
* @return ClassMetadata
*/
public function getClassMetadata(): ClassMetadata
{
@ -95,16 +87,13 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Set the object
*
* @param object $object
*
* @return AbstractCollectionStrategy
* @throws InvalidArgumentException
*/
public function setObject(object $object): AbstractCollectionStrategy
{
if (!is_object($object)) {
if (! is_object($object)) {
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
*
* @return object
*/
public function getObject(): object
{
@ -133,16 +120,14 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Return the collection by value (using the public API)
*
* @throws \InvalidArgumentException
*
* @return Collection
* @throws InvalidArgumentException
*/
protected function getCollectionFromObjectByValue(): Collection
{
$object = $this->getObject();
$getter = 'get' . ucfirst($this->getCollectionName());
if (!method_exists($object, $getter)) {
if (! method_exists($object, $getter)) {
throw new InvalidArgumentException(
sprintf(
'The getter %s to access collection %s in object %s does not exist',
@ -159,8 +144,7 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
/**
* Return the collection by reference (not using the public API)
*
* @return Collection
* @throws \ReflectionException
* @throws ReflectionException
*/
protected function getCollectionFromObjectByReference(): Collection
{
@ -173,15 +157,9 @@ abstract class AbstractCollectionStrategy implements StrategyInterface
return $reflProperty->getValue($object);
}
/**
* 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
*
* @param object $a
* @param object $b
*
* @return int
*/
protected function compareObjects(object $a, object $b): int
{

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,9 +18,14 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
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
@ -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
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
class AllowRemoveByReference extends AbstractCollectionStrategy
{
/**
* {@inheritDoc}
* @throws \ReflectionException
*
* @throws ReflectionException
*/
public function hydrate($value, $data = null): Collection
{

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,11 +18,19 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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
@ -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)
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
class AllowRemoveByValue extends AbstractCollectionStrategy
{
@ -47,7 +56,7 @@ class AllowRemoveByValue extends AbstractCollectionStrategy
$adder = 'add' . ucfirst($this->collectionName);
$remover = 'remove' . ucfirst($this->collectionName);
if (!method_exists($this->object, $adder) || !method_exists($this->object, $remover)) {
if (! method_exists($this->object, $adder) || ! method_exists($this->object, $remover)) {
throw new LogicException(
sprintf(
'AllowRemove strategy for DoctrineModule hydrator requires both %s and %s to be defined in %s
@ -63,9 +72,9 @@ class AllowRemoveByValue extends AbstractCollectionStrategy
if ($collection instanceof Collection) {
$collection = $collection->toArray();
/** @var array $collection */
}
/** @var array $collection */
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
$toRemove = new ArrayCollection(array_udiff($collection, $value, [$this, 'compareObjects']));

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,8 +18,15 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
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
* 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
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
class DisallowRemoveByReference extends AbstractCollectionStrategy
{
/**
* {@inheritDoc}
* @throws \ReflectionException
*
* @throws ReflectionException
*/
public function hydrate($value, $data = null)
public function hydrate($value, $data = null): Collection
{
$collection = $this->getCollectionFromObjectByReference();
$collectionArray = $collection->toArray();

View File

@ -1,4 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -17,11 +18,19 @@
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
namespace DoctrineMezzioModule\Hydrator\Strategy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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
@ -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)
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.7.0
* @author Michael Gallego <mic.gallego@gmail.com>
*/
class DisallowRemoveByValue extends AbstractCollectionStrategy
{
@ -46,7 +55,7 @@ class DisallowRemoveByValue extends AbstractCollectionStrategy
// AllowRemove strategy need "adder"
$adder = 'add' . ucfirst($this->collectionName);
if (!method_exists($this->object, $adder)) {
if (! method_exists($this->object, $adder)) {
throw new LogicException(
sprintf(
'DisallowRemove strategy for DoctrineModule hydrator requires %s to

View File

@ -1,27 +1,29 @@
<?php
declare(strict_types=1);
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
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.4.0
* @author Marco Pivetta <ocramius@gmail.com>
*/
class NoObjectExists extends ObjectExists
{
/**
* Error constants
*/
const ERROR_OBJECT_FOUND = 'objectFound';
public const ERROR_OBJECT_FOUND = 'objectFound';
/**
* @var array Message templates
*/
protected $messageTemplates = [
self::ERROR_OBJECT_FOUND => "An object matching '%value%' was found",
/** @var array Message templates */
protected array $messageTemplates = [
self::ERROR_OBJECT_FOUND => "An object matching '%value%' was found",
];
/**

View File

@ -4,30 +4,38 @@ declare(strict_types=1);
namespace DoctrineMezzioModule\Validator;
use Laminas\Validator\AbstractValidator;
use Laminas\Validator\Exception;
use Doctrine\Common\Persistence\ObjectRepository;
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
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 0.4.0
* @author Marco Pivetta <ocramius@gmail.com>
*/
class ObjectExists extends AbstractValidator
{
/**
* Error constants
*/
const ERROR_NO_OBJECT_FOUND = 'noObjectFound';
public const ERROR_NO_OBJECT_FOUND = 'noObjectFound';
/**
* @var array Message templates
*/
protected $messageTemplates = [
/** @var array Message templates */
protected array $messageTemplates = [
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'])) {
$provided = get_class($options['object_repository']);
} 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);
/** @phan-suppress-next-line PhanTypeComparisonToArray */
if (false === $matchedFieldsValues) { //
if (false === $matchedFieldsValues) {
throw new Exception\RuntimeException(
sprintf(
'Provided values count is %s, while expected number of fields to be matched is %s',

View File

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

View File

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

View File

@ -1,24 +1,28 @@
<?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\NoObjectExists;
use Interop\Container\ContainerInterface;
/**
* Factory for creating NoObjectExists instances
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
*/
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);

View File

@ -1,24 +1,28 @@
<?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\ObjectExists;
use Interop\Container\ContainerInterface;
/**
* Factory for creating ObjectExists instances
*
* @license MIT
* @link http://www.doctrine-project.org/
* @license MIT
*
* @since 1.3.0
* @author Fabian Grutschus <f.grutschus@lubyte.de>
*/
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);

View File

@ -1,18 +1,22 @@
<?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator\Service;
use Interop\Container\ContainerInterface;
use DoctrineMezzioModule\Validator\UniqueObject;
use Interop\Container\ContainerInterface;
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, [
'object_manager' => $this->getObjectManager($container, $options),

View File

@ -1,40 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMezzioModule\Validator;
use Doctrine\Common\Persistence\ObjectManager;
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.
*
* @license MIT
* @link http://www.doctrine-project.org/
* @author Oskar Bley <oskar@programming-php.net>
* @license MIT
*/
class UniqueObject extends ObjectExists
{
/**
* Error constants
*/
const ERROR_OBJECT_NOT_UNIQUE = 'objectNotUnique';
public const ERROR_OBJECT_NOT_UNIQUE = 'objectNotUnique';
/**
* @var array Message templates
*/
protected $messageTemplates = [
/** @var array Message templates */
protected array $messageTemplates = [
self::ERROR_OBJECT_NOT_UNIQUE => "There is already another object matching '%value%'",
];
/**
* @var ObjectManager
*/
protected $objectManager;
protected ObjectManager $objectManager;
/**
* @var boolean
*/
protected $useContext;
protected bool $useContext;
/***
* Constructor
@ -57,7 +58,7 @@ class UniqueObject extends ObjectExists
if (is_object($options['object_manager'])) {
$provided = get_class($options['object_manager']);
} 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->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 array $context
* @return boolean
*/
public function isValid($value, $context = null): bool
{
@ -97,7 +97,7 @@ class UniqueObject extends ObjectExists
$expectedIdentifiers = $this->getExpectedIdentifiers($context);
$foundIdentifiers = $this->getFoundIdentifiers($match);
if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) == 0) {
if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) === 0) {
return true;
}
@ -108,11 +108,10 @@ class UniqueObject extends ObjectExists
/**
* Gets the identifiers from the matched object.
*
* @param object $match
* @return array
* @throws Exception\RuntimeException
*/
protected function getFoundIdentifiers($match)
protected function getFoundIdentifiers(object $match): array
{
return $this->objectManager
->getClassMetadata($this->objectRepository->getClassName())
@ -126,7 +125,7 @@ class UniqueObject extends ObjectExists
* @return array
* @throws Exception\RuntimeException
*/
protected function getExpectedIdentifiers($context = null)
protected function getExpectedIdentifiers($context = null): array
{
if ($context === null) {
throw new Exception\RuntimeException(
@ -145,7 +144,7 @@ class UniqueObject extends ObjectExists
$result = [];
foreach ($this->getIdentifiers() as $identifierField) {
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];
@ -153,11 +152,10 @@ class UniqueObject extends ObjectExists
return $result;
}
/**
* @return array the names of the identifiers
*/
protected function getIdentifiers()
protected function getIdentifiers(): array
{
return $this->objectManager
->getClassMetadata($this->objectRepository->getClassName())