From d9b46219b8f7b6a6ab3dc066cd74000ca5d332bf Mon Sep 17 00:00:00 2001 From: Bill Mitchell Date: Thu, 19 Oct 2017 18:34:38 -0700 Subject: [PATCH] Clean up code --- README.md | 25 +++++++++++++++++++ composer.json | 7 +++--- .../Sniffs/TypeHints/MixedReturnTypeSniff.php | 6 ++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f3b5391..46ea7d1 100644 --- a/README.md +++ b/README.md @@ -445,6 +445,31 @@ public function bar() } ``` +### Codor.TypeHints.MixedReturnType ### +Prevents you from having a `mixed` type returned in a doc block. + +:x: +```php +/** + * @return mixed + */ +public function foo() +{ + // +} +``` + +:white_check_mark: +```php +/** + * @return string + */ +public function foo() +{ + // +} +``` + ## Customizing Sniffs ## Some of the sniff rules can be customized to your liking. For example, if you'd want the `Codor.Files.FunctionLength` to make sure your functions are no more than 30 lines instead of 20, you can do that. Here's an example of a `codor.xml` file with that customization: ```xml diff --git a/composer.json b/composer.json index 804d1b5..e9a93ca 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,7 @@ "description": "Custom PHPCS sniffs to find Code Smells.", "require": { "php": ">=7.0.0", - "squizlabs/php_codesniffer": "^2.8.1", - "roave/security-advisories": "dev-master", - "bmitch/churn-php": "^0.0.6" + "squizlabs/php_codesniffer": "^2.8.1" }, "license": "MIT", "authors": [ @@ -32,7 +30,8 @@ "slevomat/coding-standard": "^2.0", "jakub-onderka/php-console-highlighter": "^0.3.2", "jakub-onderka/php-parallel-lint": "^0.9.2", - "larapack/dd": "^1.1" + "larapack/dd": "^1.1", + "bmitch/churn-php": "~0.4.0" }, "scripts": { "test": [ diff --git a/src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php b/src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php index d7ad8c5..fc51827 100644 --- a/src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php +++ b/src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php @@ -30,7 +30,7 @@ public function register(): array * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr): void + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -50,7 +50,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr): void * * @return void */ - protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $commentStart): void + protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -99,7 +99,7 @@ private function parseTagForReturnType(array $tokens, int $returnPosition) // Support both a return type and a description. preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\a-z0-9\[\]]+))*)( .*)?`i', $content, $returnParts); - return isset($returnParts[1]) ? $returnParts[1] : false; + return $returnParts[1] ?? false; } /**