### Install Unused Public Package Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Install the package as a development dependency using Composer. ```bash composer require tomasvotruba/unused-public --dev ``` -------------------------------- ### Example of Method Call in Template Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md This example demonstrates how a public method `getTitle` might be called within a TWIG template. ```twig {{ book.getTitle() }} ``` -------------------------------- ### Example of Unused Public Method Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md This diff shows a public method `getSubtitle` that is not used within the `Book` class and is a candidate for removal or refactoring. ```diff final class Book { public function getTitle(): string { // ... } - public function getSubtitle(): string - { - // ... - } } ``` -------------------------------- ### Run PHPStan analysis Source: https://context7.com/tomasvotruba/unused-public/llms.txt Execute the analysis using the standard PHPStan command line interface. ```bash # Run PHPStan analysis vendor/bin/phpstan analyse src # Example output: # ------ -------------------------------------------------------- # Line src/Service/BookService.php # ------ -------------------------------------------------------- # 45 Public method "BookService::legacyImport()" is never used # Either reduce visibility or annotate it or its class with @api # ------ -------------------------------------------------------- # Line src/Entity/User.php # ------ -------------------------------------------------------- # 23 Public property "User::$tempField" is never used # Either reduce visibility or annotate it or its class with @api # ------ -------------------------------------------------------- ``` -------------------------------- ### Configure Unused Public in PHPStan Source: https://context7.com/tomasvotruba/unused-public/llms.txt Define detection settings for methods, properties, constants, and template paths in your phpstan.neon file. ```yaml # phpstan.neon parameters: unused_public: # Enable/disable unused public method detection (boolean or percentage threshold) methods: true # Enable detection of locally-used public methods that should be private local_methods: false # Enable/disable unused public property detection properties: true # Enable/disable unused public constant detection constants: true # Directories containing Twig/Blade templates to scan template_paths: [] ``` -------------------------------- ### Set Maximum Unused Public Percentage Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Configure a maximum percentage of public methods that are allowed to be unused. If the percentage exceeds this value, PHPStan will report an error. ```yaml parameters: unused_public: methods: 2.5 ``` -------------------------------- ### Enable Detection of Local-Only Public Methods Source: https://context7.com/tomasvotruba/unused-public/llms.txt Enable detection of public methods that are only called from within the same class. These methods should ideally be changed to private or protected visibility. ```yaml # phpstan.neon parameters: unused_public: local_methods: true ``` -------------------------------- ### Configure Template Support for Twig and Blade Source: https://context7.com/tomasvotruba/unused-public/llms.txt Configure template directories to exclude methods called from Twig or Blade templates, preventing false positives. This ensures methods used in templates are not incorrectly flagged as unused. ```yaml # phpstan.neon parameters: unused_public: methods: true template_paths: - templates - resources/views ``` -------------------------------- ### Set Relative Unused Methods Threshold Source: https://context7.com/tomasvotruba/unused-public/llms.txt Set a maximum percentage threshold for unused public methods instead of reporting each one individually. This is useful for gradually improving large codebases. ```yaml # phpstan.neon parameters: unused_public: methods: 2.5 # Allow maximum 2.5% of public methods to be unused ``` -------------------------------- ### Enable Unused Public Checks Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Configure which types of public elements (methods, properties, constants) to check for by enabling them in your PHPStan configuration. ```yaml parameters: unused_public: methods: true properties: true constants: true ``` -------------------------------- ### Exclude Methods Called in Templates Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Specify directories containing TWIG or Blade templates to prevent false positives for methods called exclusively in these templates. ```neon parameters: unused_public: template_paths: - templates ``` -------------------------------- ### Check for Local-Only Methods Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Enable this option to check for public methods that are only called locally within the same class. These might be candidates for refactoring to private or protected. ```yaml parameters: unused_public: local_methods: true ``` -------------------------------- ### Skip Public Elements with @api Annotation Source: https://github.com/tomasvotruba/unused-public/blob/main/README.md Mark public elements with the `@api` annotation to indicate they are part of the public API and should not be flagged as unused, even if not directly called within the codebase. ```php final class Book { /** * @api */ public function getName() { return $this->name; } } ``` -------------------------------- ### Enable Detection of Unused Public Methods Source: https://context7.com/tomasvotruba/unused-public/llms.txt Enable detection of public methods that are never called from outside their class. This rule reports methods that exist but are never referenced externally. ```yaml # phpstan.neon parameters: unused_public: methods: true ``` -------------------------------- ### Enable Detection of Unused Public Constants Source: https://context7.com/tomasvotruba/unused-public/llms.txt Enable detection of public constants that are never referenced from outside their class. This rule flags constants that are defined but not used elsewhere. ```yaml # phpstan.neon parameters: unused_public: constants: true ``` -------------------------------- ### Enable Detection of Unused Public Properties Source: https://context7.com/tomasvotruba/unused-public/llms.txt Enable detection of public properties that are never accessed from outside their class. This rule identifies properties that are declared but not used externally. ```yaml # phpstan.neon parameters: unused_public: properties: true ``` -------------------------------- ### Exclude elements with @api annotation Source: https://context7.com/tomasvotruba/unused-public/llms.txt Use the @api annotation on classes or methods to prevent them from being reported as unused. ```php name; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.