Conditions | 15 |
Paths | 19 |
Total Lines | 55 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 81.6765 |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
11649 | 4 | public static function substr_count_in_byte( |
|
11650 | string $haystack, |
||
11651 | string $needle, |
||
11652 | int $offset = 0, |
||
11653 | int $length = null |
||
11654 | ) { |
||
11655 | 4 | if ($haystack === '' || $needle === '') { |
|
11656 | 1 | return 0; |
|
11657 | } |
||
11658 | |||
11659 | if ( |
||
11660 | 3 | ($offset || $length !== null) |
|
11661 | && |
||
11662 | 3 | self::$SUPPORT['mbstring_func_overload'] === true |
|
11663 | ) { |
||
11664 | if ($length === null) { |
||
11665 | $length_tmp = self::strlen($haystack); |
||
11666 | if ($length_tmp === false) { |
||
11667 | return false; |
||
11668 | } |
||
11669 | $length = $length_tmp; |
||
11670 | } |
||
11671 | |||
11672 | if ( |
||
11673 | ( |
||
11674 | $length !== 0 |
||
11675 | && |
||
11676 | $offset !== 0 |
||
11677 | ) |
||
11678 | && |
||
11679 | ($length + $offset) <= 0 |
||
11680 | && |
||
11681 | \PHP_VERSION_ID < 71000 // output from "substr_count()" have changed in PHP 7.1 |
||
11682 | ) { |
||
11683 | return false; |
||
11684 | } |
||
11685 | |||
11686 | /** @var false|string $haystack_tmp - needed for PhpStan (stubs error) */ |
||
11687 | $haystack_tmp = \substr($haystack, $offset, $length); |
||
11688 | if ($haystack_tmp === false) { |
||
11689 | $haystack_tmp = ''; |
||
11690 | } |
||
11691 | $haystack = (string) $haystack_tmp; |
||
11692 | } |
||
11693 | |||
11694 | 3 | if (self::$SUPPORT['mbstring_func_overload'] === true) { |
|
11695 | // "mb_" is available if overload is used, so use it ... |
||
11696 | return \mb_substr_count($haystack, $needle, 'CP850'); // 8-BIT |
||
11697 | } |
||
11698 | |||
11699 | 3 | if ($length === null) { |
|
11700 | 3 | return \substr_count($haystack, $needle, $offset); |
|
11701 | } |
||
11702 | |||
11703 | return \substr_count($haystack, $needle, $offset, $length); |
||
11704 | } |
||
13706 |