diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 54f47ead..cc2adeaf 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -63,9 +63,7 @@ jobs: run: composer run-script cs-check - name: Run Static Analysis - run: | - composer run-script analyse - composer run-script analyse-tests + run: composer run-script analyse - name: Run Test Coverage run: composer run-script --timeout=0 test-coverage diff --git a/composer.json b/composer.json index 29693707..ba465679 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "slevomat/coding-standard": "^7.2", "phpstan/phpstan-phpunit": "^2.0", "phpstan/extension-installer": "^1.4", - "swoole/ide-helper": "^6.0" + "swoole/ide-helper": "^6.0", + "shipmonk/dead-code-detector": "^1.2" }, "minimum-stability": "dev", "prefer-stable": true, @@ -87,9 +88,6 @@ "analyse": [ "phpstan --memory-limit=-1 analyse" ], - "analyse-tests": [ - "phpstan --memory-limit=-1 analyse -c phpstan.tests.neon" - ], "cs-check": [ "phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src --runtime-set ignore_warnings_on_exit 1", "ecs check" diff --git a/phpstan.neon b/phpstan.neon index d23dec32..82f2f3b3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,21 @@ +services: + - + class: Tests\Support\FreeDSx\Ldap\PhpStan\ApiMemberUsageProvider + tags: + - shipmonk.deadCode.memberUsageProvider + parameters: - level: 9 + level: 10 paths: - %currentWorkingDirectory%/src + - %currentWorkingDirectory%/tests scanDirectories: - %currentWorkingDirectory%/vendor/swoole/ide-helper/src treatPhpDocTypesAsCertain: false reportUnmatchedIgnoredErrors: false ignoreErrors: - '#Unsafe usage of new static\(\).#' + shipmonkDeadCode: + usageProviders: + phpunit: + enabled: true diff --git a/phpstan.tests.neon b/phpstan.tests.neon deleted file mode 100644 index 09871428..00000000 --- a/phpstan.tests.neon +++ /dev/null @@ -1,5 +0,0 @@ -parameters: - treatPhpDocTypesAsCertain: false - level: 10 - paths: - - %currentWorkingDirectory%/tests diff --git a/src/FreeDSx/Ldap/ClientOptions.php b/src/FreeDSx/Ldap/ClientOptions.php index a6561840..ab3d1b0d 100644 --- a/src/FreeDSx/Ldap/ClientOptions.php +++ b/src/FreeDSx/Ldap/ClientOptions.php @@ -15,6 +15,9 @@ use FreeDSx\Ldap\Control\ControlBag; +/** + * @api + */ final class ClientOptions { private int $version = 3; diff --git a/src/FreeDSx/Ldap/Container.php b/src/FreeDSx/Ldap/Container.php index fb385e5f..c796e0ee 100644 --- a/src/FreeDSx/Ldap/Container.php +++ b/src/FreeDSx/Ldap/Container.php @@ -109,6 +109,13 @@ public function get(string $className): object } $instance = ($this->instanceFactory[$className])(); + if (!$instance instanceof $className) { + throw new RuntimeException(sprintf( + 'The factory for "%s" did not return the expected type.', + $className, + )); + } + if (!in_array($className, self::FACTORY_ONLY, true)) { $this->instances[$className] = $instance; } diff --git a/src/FreeDSx/Ldap/Control/Ad/DirSyncRequestControl.php b/src/FreeDSx/Ldap/Control/Ad/DirSyncRequestControl.php index 650ded33..c75da035 100644 --- a/src/FreeDSx/Ldap/Control/Ad/DirSyncRequestControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/DirSyncRequestControl.php @@ -32,6 +32,8 @@ * Cookie OCTET STRING * } * + * @api + * * @see https://msdn.microsoft.com/en-us/library/cc223347.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/DirSyncResponseControl.php b/src/FreeDSx/Ldap/Control/Ad/DirSyncResponseControl.php index b4023e67..c15b83e1 100644 --- a/src/FreeDSx/Ldap/Control/Ad/DirSyncResponseControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/DirSyncResponseControl.php @@ -32,6 +32,8 @@ * CookieServer OCTET STRING * } * + * @api + * * @see https://msdn.microsoft.com/en-us/library/cc223347.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/ExpectedEntryCountControl.php b/src/FreeDSx/Ldap/Control/Ad/ExpectedEntryCountControl.php index 8b53a709..76d41416 100644 --- a/src/FreeDSx/Ldap/Control/Ad/ExpectedEntryCountControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/ExpectedEntryCountControl.php @@ -31,6 +31,8 @@ * searchEntriesMax INTEGER * } * + * @api + * * @see https://msdn.microsoft.com/en-us/library/jj216720.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php b/src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php index 163e95f2..f62cfcc1 100644 --- a/src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php @@ -27,6 +27,8 @@ /** * Used to represent the Extended DN control. * + * @api + * * @see https://msdn.microsoft.com/en-us/library/cc223349.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/PolicyHintsControl.php b/src/FreeDSx/Ldap/Control/Ad/PolicyHintsControl.php index 231ac7d7..93aa41e8 100644 --- a/src/FreeDSx/Ldap/Control/Ad/PolicyHintsControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/PolicyHintsControl.php @@ -29,6 +29,8 @@ * Flags INTEGER * } * + * @api + * * @see https://msdn.microsoft.com/en-us/library/hh128228.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/SdFlagsControl.php b/src/FreeDSx/Ldap/Control/Ad/SdFlagsControl.php index 0d6a7f36..641f0181 100644 --- a/src/FreeDSx/Ldap/Control/Ad/SdFlagsControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/SdFlagsControl.php @@ -24,6 +24,8 @@ * Flags INTEGER * } * + * @api + * * @see https://msdn.microsoft.com/en-us/library/cc223323.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/Ad/SetOwnerControl.php b/src/FreeDSx/Ldap/Control/Ad/SetOwnerControl.php index fe78b87d..092d7cbc 100644 --- a/src/FreeDSx/Ldap/Control/Ad/SetOwnerControl.php +++ b/src/FreeDSx/Ldap/Control/Ad/SetOwnerControl.php @@ -27,6 +27,8 @@ * * SID octetString * + * @api + * * https://msdn.microsoft.com/en-us/library/dn392490.aspx * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/AssertionControl.php b/src/FreeDSx/Ldap/Control/AssertionControl.php index f934e5e6..bd6e7271 100644 --- a/src/FreeDSx/Ldap/Control/AssertionControl.php +++ b/src/FreeDSx/Ldap/Control/AssertionControl.php @@ -23,6 +23,8 @@ * * The operation proceeds only if the filter matches the target entry. * + * @api + * * @author Chad Sikorra */ class AssertionControl extends Control diff --git a/src/FreeDSx/Ldap/Control/Control.php b/src/FreeDSx/Ldap/Control/Control.php index f27a829d..6a840832 100644 --- a/src/FreeDSx/Ldap/Control/Control.php +++ b/src/FreeDSx/Ldap/Control/Control.php @@ -35,6 +35,8 @@ * criticality BOOLEAN DEFAULT FALSE, * controlValue OCTET STRING OPTIONAL } * + * @api + * * @author Chad Sikorra */ class Control implements ProtocolElementInterface, Stringable diff --git a/src/FreeDSx/Ldap/Control/ControlBag.php b/src/FreeDSx/Ldap/Control/ControlBag.php index 59902318..49fcdd7f 100644 --- a/src/FreeDSx/Ldap/Control/ControlBag.php +++ b/src/FreeDSx/Ldap/Control/ControlBag.php @@ -26,6 +26,8 @@ /** * Represents a set of controls. * + * @api + * * @implements IteratorAggregate * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Control/PagingControl.php b/src/FreeDSx/Ldap/Control/PagingControl.php index cdae3b12..74bee15e 100644 --- a/src/FreeDSx/Ldap/Control/PagingControl.php +++ b/src/FreeDSx/Ldap/Control/PagingControl.php @@ -31,6 +31,8 @@ * -- result set size estimate from server * cookie OCTET STRING } * + * @api + * * @author Chad Sikorra */ class PagingControl extends Control diff --git a/src/FreeDSx/Ldap/Control/ProxyAuthorizationControl.php b/src/FreeDSx/Ldap/Control/ProxyAuthorizationControl.php index 6ec87eb8..2481eaf7 100644 --- a/src/FreeDSx/Ldap/Control/ProxyAuthorizationControl.php +++ b/src/FreeDSx/Ldap/Control/ProxyAuthorizationControl.php @@ -20,6 +20,8 @@ /** * Represents a proxied authorization control. RFC 4370. * + * @api + * * @author Chad Sikorra */ final class ProxyAuthorizationControl extends Control diff --git a/src/FreeDSx/Ldap/Control/PwdPolicyResponseControl.php b/src/FreeDSx/Ldap/Control/PwdPolicyResponseControl.php index 05228704..3870b432 100644 --- a/src/FreeDSx/Ldap/Control/PwdPolicyResponseControl.php +++ b/src/FreeDSx/Ldap/Control/PwdPolicyResponseControl.php @@ -40,6 +40,8 @@ * passwordTooYoung (7), * passwordInHistory (8) } OPTIONAL } * + * @api + * * @author Chad Sikorra */ class PwdPolicyResponseControl extends Control diff --git a/src/FreeDSx/Ldap/Control/ReadEntry/ReadEntryResponseControl.php b/src/FreeDSx/Ldap/Control/ReadEntry/ReadEntryResponseControl.php index 5af55d1c..36631eb9 100644 --- a/src/FreeDSx/Ldap/Control/ReadEntry/ReadEntryResponseControl.php +++ b/src/FreeDSx/Ldap/Control/ReadEntry/ReadEntryResponseControl.php @@ -24,6 +24,8 @@ * * Carries the entry state as a SearchResultEntry. * + * @api + * * @author Chad Sikorra */ abstract class ReadEntryResponseControl extends Control diff --git a/src/FreeDSx/Ldap/Control/Sorting/SortKey.php b/src/FreeDSx/Ldap/Control/Sorting/SortKey.php index ac53686c..d1ce2295 100644 --- a/src/FreeDSx/Ldap/Control/Sorting/SortKey.php +++ b/src/FreeDSx/Ldap/Control/Sorting/SortKey.php @@ -16,6 +16,8 @@ /** * Represents a server side sorting request SortKey. * + * @api + * * @author Chad Sikorra */ class SortKey diff --git a/src/FreeDSx/Ldap/Control/Sorting/SortingControl.php b/src/FreeDSx/Ldap/Control/Sorting/SortingControl.php index 4cf4381b..66c7a669 100644 --- a/src/FreeDSx/Ldap/Control/Sorting/SortingControl.php +++ b/src/FreeDSx/Ldap/Control/Sorting/SortingControl.php @@ -33,6 +33,8 @@ * orderingRule [0] MatchingRuleId OPTIONAL, * reverseOrder [1] BOOLEAN DEFAULT FALSE } * + * @api + * * @author Chad Sikorra */ class SortingControl extends Control diff --git a/src/FreeDSx/Ldap/Control/Sorting/SortingResponseControl.php b/src/FreeDSx/Ldap/Control/Sorting/SortingResponseControl.php index 4dc88c70..32913cec 100644 --- a/src/FreeDSx/Ldap/Control/Sorting/SortingResponseControl.php +++ b/src/FreeDSx/Ldap/Control/Sorting/SortingResponseControl.php @@ -49,6 +49,8 @@ * }, * attributeType [0] AttributeDescription OPTIONAL } * + * @api + * * @author Chad Sikorra */ class SortingResponseControl extends Control diff --git a/src/FreeDSx/Ldap/Control/SubentriesControl.php b/src/FreeDSx/Ldap/Control/SubentriesControl.php index 9f7a2452..80f78ffb 100644 --- a/src/FreeDSx/Ldap/Control/SubentriesControl.php +++ b/src/FreeDSx/Ldap/Control/SubentriesControl.php @@ -22,6 +22,8 @@ /** * Represents a subentries control. RFC 3672. * + * @api + * * @author Chad Sikorra */ class SubentriesControl extends Control diff --git a/src/FreeDSx/Ldap/Control/Sync/SyncDoneControl.php b/src/FreeDSx/Ldap/Control/Sync/SyncDoneControl.php index 5cfc30a5..3337b817 100644 --- a/src/FreeDSx/Ldap/Control/Sync/SyncDoneControl.php +++ b/src/FreeDSx/Ldap/Control/Sync/SyncDoneControl.php @@ -31,6 +31,8 @@ * refreshDeletes BOOLEAN DEFAULT FALSE * } * + * @api + * * @author Chad Sikorra */ class VlvControl extends Control diff --git a/src/FreeDSx/Ldap/Control/Vlv/VlvResponseControl.php b/src/FreeDSx/Ldap/Control/Vlv/VlvResponseControl.php index 6b673a82..59e72e5f 100644 --- a/src/FreeDSx/Ldap/Control/Vlv/VlvResponseControl.php +++ b/src/FreeDSx/Ldap/Control/Vlv/VlvResponseControl.php @@ -45,6 +45,8 @@ * ... }, * contextID OCTET STRING OPTIONAL } * + * @api + * * @author Chad Sikorra */ class VlvResponseControl extends Control diff --git a/src/FreeDSx/Ldap/Controls.php b/src/FreeDSx/Ldap/Controls.php index 832b92f4..a509374d 100644 --- a/src/FreeDSx/Ldap/Controls.php +++ b/src/FreeDSx/Ldap/Controls.php @@ -38,6 +38,8 @@ /** * Provides some simple factory methods for building controls. * + * @api + * * @author Chad Sikorra */ class Controls diff --git a/src/FreeDSx/Ldap/Entry/Attribute.php b/src/FreeDSx/Ldap/Entry/Attribute.php index e111c3fa..e68c0857 100644 --- a/src/FreeDSx/Ldap/Entry/Attribute.php +++ b/src/FreeDSx/Ldap/Entry/Attribute.php @@ -33,6 +33,8 @@ /** * Represents an entry attribute and any values. * + * @api + * * @implements IteratorAggregate * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Entry/Change.php b/src/FreeDSx/Ldap/Entry/Change.php index d6a25e69..3f730e8f 100644 --- a/src/FreeDSx/Ldap/Entry/Change.php +++ b/src/FreeDSx/Ldap/Entry/Change.php @@ -18,6 +18,8 @@ /** * Represents an entry change. * + * @api + * * @author Chad Sikorra */ class Change diff --git a/src/FreeDSx/Ldap/Entry/Changes.php b/src/FreeDSx/Ldap/Entry/Changes.php index aa8c5fdb..fba2b6c8 100644 --- a/src/FreeDSx/Ldap/Entry/Changes.php +++ b/src/FreeDSx/Ldap/Entry/Changes.php @@ -24,6 +24,8 @@ /** * Represents a set of change objects. * + * @api + * * @implements IteratorAggregate * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Entry/Entries.php b/src/FreeDSx/Ldap/Entry/Entries.php index 9dc4c5fa..5ced356e 100644 --- a/src/FreeDSx/Ldap/Entry/Entries.php +++ b/src/FreeDSx/Ldap/Entry/Entries.php @@ -29,6 +29,8 @@ /** * Represents a collection of entry objects. * + * @api + * * @author Chad Sikorra * * @implements IteratorAggregate diff --git a/src/FreeDSx/Ldap/Entry/Entry.php b/src/FreeDSx/Ldap/Entry/Entry.php index 5dcbdb7d..9f115938 100644 --- a/src/FreeDSx/Ldap/Entry/Entry.php +++ b/src/FreeDSx/Ldap/Entry/Entry.php @@ -26,6 +26,8 @@ /** * Represents an Entry in LDAP. * + * @api + * * @implements IteratorAggregate * @author Chad Sikorra */ diff --git a/src/FreeDSx/Ldap/Entry/EscapeTrait.php b/src/FreeDSx/Ldap/Entry/EscapeTrait.php index d5ebeca0..ba946357 100644 --- a/src/FreeDSx/Ldap/Entry/EscapeTrait.php +++ b/src/FreeDSx/Ldap/Entry/EscapeTrait.php @@ -22,12 +22,16 @@ /** * Some common methods around escaping attribute values and RDN values. * + * @api + * * @author Chad Sikorra */ trait EscapeTrait { /** * Escape all characters in a value. + * + * @api */ public static function escapeAll(string $value): string { diff --git a/src/FreeDSx/Ldap/Entry/Option.php b/src/FreeDSx/Ldap/Entry/Option.php index 830bdec3..f6394c73 100644 --- a/src/FreeDSx/Ldap/Entry/Option.php +++ b/src/FreeDSx/Ldap/Entry/Option.php @@ -22,6 +22,8 @@ /** * Represents an attribute option. Described in RFC 4512, Section 2.5.2. * + * @api + * * @author Chad Sikorra */ class Option implements Stringable diff --git a/src/FreeDSx/Ldap/Entry/Options.php b/src/FreeDSx/Ldap/Entry/Options.php index e00cac0a..8f432c84 100644 --- a/src/FreeDSx/Ldap/Entry/Options.php +++ b/src/FreeDSx/Ldap/Entry/Options.php @@ -25,6 +25,8 @@ /** * Represents a collection of attribute options. * + * @api + * * @implements IteratorAggregate