Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
bmitch committed Oct 20, 2017
1 parent 97f54bf commit d9b4621
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": [
Expand Down
6 changes: 3 additions & 3 deletions src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit d9b4621

Please sign in to comment.