| Conditions | 7 |
| Paths | 7 |
| Total Lines | 53 |
| Code Lines | 28 |
| 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 |
||
| 54 | protected function updateVersions() |
||
| 55 | { |
||
| 56 | // Get decorated classes |
||
| 57 | $dataObjectSublasses = ClassInfo::getValidSubClasses(DataObject::class); |
||
| 58 | $candidates = []; |
||
| 59 | |||
| 60 | foreach ($dataObjectSublasses as $class) { |
||
| 61 | $obj = Injector::inst()->create($class); |
||
| 62 | |||
| 63 | if (!$obj->hasExtension(VerifiableExtension::class)) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->log('NOTICE', "Processing class: $class"); |
||
| 68 | |||
| 69 | foreach ($class::get() as $item) { |
||
| 70 | // TODO Get all versions that have non-duplicated proof-hashes |
||
| 71 | $versions = Versioned::get_all_versions($class, $item->ID)->sort('Version ASC'); |
||
| 72 | |||
| 73 | foreach ($versions as $record) { |
||
| 74 | $proof = $record->dbObject('Proof'); |
||
| 75 | |||
| 76 | if ($proof->isInitial()) { |
||
| 77 | $this->log('NOTICE', "\tInitial proof found for ID #{$record->RecordID} and version {$record->Version}"); |
||
| 78 | $this->log('NOTICE', "\tRequesting proof via UUID {$proof->getHashIdNode()[0]}"); |
||
| 79 | |||
| 80 | // I don't understand the Tierion network... if we submit a hash to one IP |
||
| 81 | // the rest of the network is not updated. So we need to pre-seed the service |
||
| 82 | // with the saved nodes...unless it's only verified proofs that get propagated..?? |
||
| 83 | $nodes = $record->dbObject('Extra')->getStoreAsArray(); |
||
| 84 | $uuid = $proof->getHashIdNode()[0]; |
||
| 85 | $this->verifiableService->setExtra($nodes); |
||
| 86 | |||
| 87 | $this->log('NOTICE', sprintf('Calling %s/proofs/%s', $nodes[0], $uuid)); |
||
| 88 | |||
| 89 | // Don't attempt to write anything that isn't a full proof |
||
| 90 | $response = $this->verifiableService->call('read', $uuid); |
||
| 91 | $isFull = ChainpointProof::create() |
||
| 92 | ->setValue($response) |
||
| 93 | ->isFull(); |
||
| 94 | |||
| 95 | if ($isFull) { |
||
| 96 | $this->log('NOTICE', "Full proof fetched. Updating record with ID #{$record->RecordID} and version $version"); |
||
| 97 | $this->updateQuery($record, $version, $response); |
||
| 98 | } else { |
||
| 99 | $this->log('WARN', "No full proof found for record with ID #{$record->RecordID} and version $version"); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $candidates; |
||
| 107 | } |
||
| 147 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.