| Conditions | 8 |
| Paths | 1 |
| Total Lines | 62 |
| Lines | 3 |
| Ratio | 4.84 % |
| 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 |
||
| 91 | public function initSlave($point) |
||
| 92 | { |
||
| 93 | $this->db->{'local.oplog.$main'}->find( |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param \MongoTimestamp $cursor |
||
| 97 | */ |
||
| 98 | function ($cursor) { |
||
| 99 | $this->cursor = $cursor; |
||
| 100 | $cursor->state = 1; |
||
| 101 | $cursor->lastOpId = null; |
||
| 102 | |||
| 103 | foreach ($cursor->items as $k => &$item) { |
||
| 104 | View Code Duplication | if (\PHPDaemon\Core\Daemon::$config->logevents->value) { |
|
| 105 | \PHPDaemon\Core\Daemon::log(get_class($this) . ': caught oplog-record with ts = (' . \PHPDaemon\Core\Debug::dump($item['ts']) . ')'); |
||
| 106 | } |
||
| 107 | |||
| 108 | $cursor->lastOpId = $item['ts']; |
||
| 109 | |||
| 110 | if ($item['op'] === 'i') { |
||
| 111 | $this->cacheObject($item['o']); |
||
| 112 | } elseif ($item['op'] === 'd') { |
||
| 113 | $this->deleteObject($item['o']); |
||
| 114 | } elseif ($item['op'] === 'u') { |
||
| 115 | if ( |
||
| 116 | isset($item['b']) |
||
| 117 | && ($item['b'] === false) |
||
| 118 | ) { |
||
| 119 | $item['o']['_id'] = $item['o2']['_id']; |
||
| 120 | $this->cacheObject($item['o']); |
||
| 121 | } else { |
||
| 122 | $cursor->appInstance->{$item['ns']}->findOne( |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param \MongoTimestamp $item |
||
| 126 | */ |
||
| 127 | function ($item) { |
||
| 128 | $this->cacheObject($item); |
||
| 129 | }, |
||
| 130 | ['where' => ['_id' => $item['o2']['_id']]] |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | unset($cursor->items[$k]); |
||
| 136 | } |
||
| 137 | }, [ |
||
| 138 | 'tailable' => true, |
||
| 139 | 'sort' => ['$natural' => 1], |
||
| 140 | 'snapshot' => 1, |
||
| 141 | 'where' => [ |
||
| 142 | 'ts' => [ |
||
| 143 | '$gt' => $point |
||
| 144 | ], |
||
| 145 | '$exists' => [ |
||
| 146 | '_key' => true |
||
| 147 | ] |
||
| 148 | ], |
||
| 149 | 'parse_oplog' => true, |
||
| 150 | ] |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 213 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.