| Conditions | 16 |
| Paths | 432 |
| Total Lines | 57 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 40 | public function isPublic($category, array $tags) |
||
| 41 | { |
||
| 42 | $isPublic = false; |
||
| 43 | |||
| 44 | // publish if no public categories are specified. |
||
| 45 | if (empty($this->publicCategories)) { |
||
| 46 | $isPublic = true; |
||
| 47 | } |
||
| 48 | |||
| 49 | // publish if no public tags are specified. |
||
| 50 | if (empty($this->publicTags)) { |
||
| 51 | $isPublic = true; |
||
| 52 | } |
||
| 53 | |||
| 54 | // publish if category is under one of public categories. |
||
| 55 | if (!$isPublic) { |
||
| 56 | foreach ($this->publicCategories as $publicCategory) { |
||
| 57 | if (preg_match(sprintf('#^%s#', $publicCategory), $category)) { |
||
| 58 | $isPublic = true; |
||
| 59 | break; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | // publish if at least one tag is one of public tags. |
||
| 65 | if (!$isPublic) { |
||
| 66 | foreach ($this->publicTags as $publicTag) { |
||
| 67 | foreach ($tags as $tag) { |
||
| 68 | if (preg_match(sprintf('/%s/', $publicTag), $tag)) { |
||
| 69 | $isPublic = true; |
||
| 70 | break 2; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | // unpublish if category is under one of private categories. |
||
| 77 | foreach ($this->privateCategories as $privateCategory) { |
||
| 78 | if (preg_match(sprintf('#^%s#', $privateCategory), $category)) { |
||
| 79 | $isPublic = false; |
||
| 80 | break; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | // unpublish if at least one tag is one of private tags. |
||
| 85 | if ($isPublic) { |
||
| 86 | foreach ($this->privateTags as $privateTag) { |
||
| 87 | foreach ($tags as $tag) { |
||
| 88 | if (preg_match(sprintf('/%s/', $privateTag), $tag)) { |
||
| 89 | $isPublic = false; |
||
| 90 | break 2; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | return $isPublic; |
||
| 97 | } |
||
| 143 |