| @@ -157,6 +157,9 @@ | ||
| 157 | 157 | } | 
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | + /** | |
| 161 | + * @param string $relativePath | |
| 162 | + */ | |
| 160 | 163 | protected function getAbsolutePath($relativePath): string | 
| 161 | 164 |      { | 
| 162 | 165 | return $this->remotePath . ltrim($relativePath, DIRECTORY_SEPARATOR); | 
| @@ -69,7 +69,7 @@ discard block | ||
| 69 | 69 | sleep(5); | 
| 70 | 70 | } | 
| 71 | 71 | } | 
| 72 | - while($wait); | |
| 72 | + while ($wait); | |
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | 75 | // only write lock if no other exists (or $force is true) | 
| @@ -115,7 +115,7 @@ discard block | ||
| 115 | 115 |          { | 
| 116 | 116 | @fclose($this->getStream($relativePath, 'r')); | 
| 117 | 117 | } | 
| 118 | - catch(\RuntimeException $exception) | |
| 118 | + catch (\RuntimeException $exception) | |
| 119 | 119 |          { | 
| 120 | 120 | return false; | 
| 121 | 121 | } | 
| @@ -114,8 +114,7 @@ | ||
| 114 | 114 | try | 
| 115 | 115 |          { | 
| 116 | 116 | @fclose($this->getStream($relativePath, 'r')); | 
| 117 | - } | |
| 118 | - catch(\RuntimeException $exception) | |
| 117 | + } catch(\RuntimeException $exception) | |
| 119 | 118 |          { | 
| 120 | 119 | return false; | 
| 121 | 120 | } | 
| @@ -319,6 +319,9 @@ discard block | ||
| 319 | 319 | return $operationCollection; | 
| 320 | 320 | } | 
| 321 | 321 | |
| 322 | + /** | |
| 323 | + * @param resource $stream | |
| 324 | + */ | |
| 322 | 325 | protected function readIndexFromStream($stream, \DateTime $created = null): Index | 
| 323 | 326 |      { | 
| 324 | 327 | $index = new Index($created); | 
| @@ -331,6 +334,9 @@ discard block | ||
| 331 | 334 | return $index; | 
| 332 | 335 | } | 
| 333 | 336 | |
| 337 | + /** | |
| 338 | + * @param resource $stream | |
| 339 | + */ | |
| 334 | 340 | protected function writeIndexToStream(Index $index, $stream) | 
| 335 | 341 |      { | 
| 336 | 342 | foreach ($index as $object) | 
| @@ -267,7 +267,7 @@ discard block | ||
| 267 | 267 |                      { | 
| 268 | 268 | $blobId = $mergedIndex->generateNewBlobId(); | 
| 269 | 269 | } | 
| 270 | - while($this->vaultConnection->exists($blobId)); | |
| 270 | + while ($this->vaultConnection->exists($blobId)); | |
| 271 | 271 | |
| 272 | 272 | $indexObject->setBlobId($blobId); | 
| 273 | 273 | |
| @@ -323,7 +323,7 @@ discard block | ||
| 323 | 323 |      { | 
| 324 | 324 | $index = new Index($created); | 
| 325 | 325 | |
| 326 | - while(($row = fgetcsv($stream)) !== false) | |
| 326 | + while (($row = fgetcsv($stream)) !== false) | |
| 327 | 327 |          { | 
| 328 | 328 | $index->addObject(IndexObject::fromIndexRecord($row)); | 
| 329 | 329 | } | 
| @@ -232,8 +232,7 @@ discard block | ||
| 232 | 232 | if ($localObject === null) | 
| 233 | 233 |                  { | 
| 234 | 234 | $operationCollection->addOperation(new MkdirOperation($absoluteLocalPath, $indexObject->getMode())); | 
| 235 | - } | |
| 236 | - elseif (!$localObject->isDirectory()) | |
| 235 | + } elseif (!$localObject->isDirectory()) | |
| 237 | 236 |                  { | 
| 238 | 237 | $operationCollection->addOperation(new MkdirOperation($absoluteLocalPath, $indexObject->getMode())); | 
| 239 | 238 | } | 
| @@ -245,9 +244,7 @@ discard block | ||
| 245 | 244 | $directoryMtimes[$absoluteLocalPath] = $indexObject->getMtime(); | 
| 246 | 245 | } | 
| 247 | 246 | } | 
| 248 | - } | |
| 249 | - | |
| 250 | - elseif ($indexObject->isFile()) | |
| 247 | + } elseif ($indexObject->isFile()) | |
| 251 | 248 |              { | 
| 252 | 249 | // local file did not exist, hasn't been a file before or is outdated | 
| 253 | 250 | if ($localObject === null || !$localObject->isFile() || $localObject->getMtime() < $indexObject->getMtime()) | 
| @@ -273,9 +270,7 @@ discard block | ||
| 273 | 270 | |
| 274 | 271 | $operationCollection->addOperation(new UploadOperation($absoluteLocalPath, $indexObject->getBlobId(), $this->vaultConnection)); | 
| 275 | 272 | } | 
| 276 | - } | |
| 277 | - | |
| 278 | - elseif ($indexObject->isLink()) | |
| 273 | + } elseif ($indexObject->isLink()) | |
| 279 | 274 |              { | 
| 280 | 275 | $absoluteLinkTarget = dirname($absoluteLocalPath) . DIRECTORY_SEPARATOR . $indexObject->getLinkTarget(); | 
| 281 | 276 | |
| @@ -284,9 +279,7 @@ discard block | ||
| 284 | 279 | $operationCollection->addOperation(new UnlinkOperation($absoluteLocalPath)); | 
| 285 | 280 | $operationCollection->addOperation(new SymlinkOperation($absoluteLocalPath, $absoluteLinkTarget, $indexObject->getMode())); | 
| 286 | 281 | } | 
| 287 | - } | |
| 288 | - | |
| 289 | - else | |
| 282 | + } else | |
| 290 | 283 |              { | 
| 291 | 284 | // unknown object type | 
| 292 | 285 | throw new \RuntimeException(); | 
| @@ -161,17 +161,14 @@ | ||
| 161 | 161 | if (is_file($absolutePath)) | 
| 162 | 162 |          { | 
| 163 | 163 | $object->type = static::TYPE_FILE; | 
| 164 | - } | |
| 165 | - elseif (is_dir($absolutePath)) | |
| 164 | + } elseif (is_dir($absolutePath)) | |
| 166 | 165 |          { | 
| 167 | 166 | $object->type = static::TYPE_DIR; | 
| 168 | - } | |
| 169 | - elseif (is_link($absolutePath)) | |
| 167 | + } elseif (is_link($absolutePath)) | |
| 170 | 168 |          { | 
| 171 | 169 | $object->type = static::TYPE_LINK; | 
| 172 | 170 | $object->linkTarget = str_replace($basePath, '', readlink($absolutePath)); | 
| 173 | - } | |
| 174 | - else | |
| 171 | + } else | |
| 175 | 172 |          { | 
| 176 | 173 |              throw new \InvalidArgumentException(sprintf('File %s does not exist!', $absolutePath)); | 
| 177 | 174 | } | 
| @@ -26,8 +26,7 @@ | ||
| 26 | 26 | if (count($operationCollection)) | 
| 27 | 27 |          { | 
| 28 | 28 |              $output->writeln(sprintf('<info>There are %d outstanding operations!</info>', count($operationCollection))); | 
| 29 | - } | |
| 30 | - else | |
| 29 | + } else | |
| 31 | 30 |          { | 
| 32 | 31 |              $output->writeln('<info>Everything is up to date!</info>'); | 
| 33 | 32 | } | 
| @@ -48,8 +48,7 @@ | ||
| 48 | 48 |          { | 
| 49 | 49 | $factory = new JsonFileConfigurationFactory($path); | 
| 50 | 50 | return $factory(); | 
| 51 | - } | |
| 52 | - else | |
| 51 | + } else | |
| 53 | 52 |          { | 
| 54 | 53 |              throw new \InvalidArgumentException(sprintf('Don\'t know how to handle configuration given file %s.', $path)); | 
| 55 | 54 | } | 
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 |          { | 
| 84 | 84 | $blobId = Uuid::uuid4(); | 
| 85 | 85 | } | 
| 86 | - while($this->getObjectByBlobId($blobId) !== null); | |
| 86 | + while ($this->getObjectByBlobId($blobId) !== null); | |
| 87 | 87 | |
| 88 | 88 | return $blobId; | 
| 89 | 89 | } | 
| @@ -37,8 +37,7 @@ | ||
| 37 | 37 | if ($parent === null) | 
| 38 | 38 |              { | 
| 39 | 39 | throw new \InvalidArgumentException(); | 
| 40 | - } | |
| 41 | - elseif (!$parent->isDirectory()) | |
| 40 | + } elseif (!$parent->isDirectory()) | |
| 42 | 41 |              { | 
| 43 | 42 | throw new \InvalidArgumentException(); | 
| 44 | 43 | } | 
| @@ -25,13 +25,11 @@ discard block | ||
| 25 | 25 | if ($localObjectModified) | 
| 26 | 26 |                  { | 
| 27 | 27 | $mergedIndex->addObject($localObject); | 
| 28 | - } | |
| 29 | - elseif ($remoteIndex === null) | |
| 28 | + } elseif ($remoteIndex === null) | |
| 30 | 29 |                  { | 
| 31 | 30 | $mergedIndex->addObject($localObject); | 
| 32 | 31 | } | 
| 33 | - } | |
| 34 | - else | |
| 32 | + } else | |
| 35 | 33 |              { | 
| 36 | 34 | // todo: merge mode by ctime | 
| 37 | 35 | |
| @@ -40,14 +38,10 @@ discard block | ||
| 40 | 38 | if (!$localObjectModified) | 
| 41 | 39 |                  { | 
| 42 | 40 | $mergedIndex->addObject($remoteObject); | 
| 43 | - } | |
| 44 | - | |
| 45 | - elseif (!$remoteObjectModified) | |
| 41 | + } elseif (!$remoteObjectModified) | |
| 46 | 42 |                  { | 
| 47 | 43 | $mergedIndex->addObject($localObject); | 
| 48 | - } | |
| 49 | - | |
| 50 | - else | |
| 44 | + } else | |
| 51 | 45 |                  { | 
| 52 | 46 | // todo: properly handle collision | 
| 53 | 47 |                      throw new \RuntimeException("Collision at path {$localObject->getRelativePath()}"); |