@@ -7,7 +7,6 @@ |
||
| 7 | 7 | |
| 8 | 8 | use Symfony\Component\Console\Command\Command; |
| 9 | 9 | use Symfony\Component\Console\Input\InputArgument; |
| 10 | - |
|
| 11 | 10 | use Symfony\Component\Console\Input\InputInterface; |
| 12 | 11 | use Symfony\Component\Console\Input\InputOption; |
| 13 | 12 | use Symfony\Component\Console\Output\OutputInterface; |
@@ -97,7 +97,7 @@ |
||
| 97 | 97 | /** |
| 98 | 98 | * import a single file into a collection |
| 99 | 99 | * |
| 100 | - * @param SplFileInfo $file file |
|
| 100 | + * @param \SplFileInfo $file file |
|
| 101 | 101 | * @param InputInterface $input User input on console |
| 102 | 102 | * @param OutputInterface $output Output of the command |
| 103 | 103 | * |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param InputInterface $input User input on console |
| 143 | 143 | * @param OutputInterface $output Output of the command |
| 144 | 144 | * |
| 145 | - * @return void |
|
| 145 | + * @return integer |
|
| 146 | 146 | */ |
| 147 | 147 | protected function doImport(Finder $finder, InputInterface $input, OutputInterface $output) |
| 148 | 148 | { |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param string $rewriteTo string to replace value from $rewriteHost with during loading |
| 233 | 233 | * @param boolean $sync send requests syncronously |
| 234 | 234 | * |
| 235 | - * @return Promise\Promise|null |
|
| 235 | + * @return Promise\PromiseInterface |
|
| 236 | 236 | */ |
| 237 | 237 | protected function importResource( |
| 238 | 238 | $targetUrl, |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | * @param Document $doc Data source for import data |
| 361 | 361 | * @param string $originFile Original full filename used toimport |
| 362 | - * @return bool|mixed |
|
| 362 | + * @return false|string |
|
| 363 | 363 | */ |
| 364 | 364 | private function validateUploadFile(Document $doc, $originFile) |
| 365 | 365 | { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $output->writeln("<info>Loading data from ${file}</info>"); |
| 227 | 227 | |
| 228 | 228 | if (!array_key_exists('target', $doc->getData())) { |
| 229 | - throw new MissingTargetException('Missing target in \'' . $file . '\''); |
|
| 229 | + throw new MissingTargetException('Missing target in \''.$file.'\''); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | $targetUrl = sprintf('%s%s', $host, $doc->getData()['target']); |
@@ -272,16 +272,16 @@ discard block |
||
| 272 | 272 | $content = str_replace($rewriteHost, $rewriteTo, $doc->getContent()); |
| 273 | 273 | $uploadFile = $this->validateUploadFile($doc, $file); |
| 274 | 274 | |
| 275 | - $successFunc = function (ResponseInterface $response) use ($output) { |
|
| 275 | + $successFunc = function(ResponseInterface $response) use ($output) { |
|
| 276 | 276 | $output->writeln( |
| 277 | - '<comment>Wrote ' . $response->getHeader('Link')[0] . '</comment>' |
|
| 277 | + '<comment>Wrote '.$response->getHeader('Link')[0].'</comment>' |
|
| 278 | 278 | ); |
| 279 | 279 | }; |
| 280 | 280 | |
| 281 | - $errFunc = function (RequestException $e) use ($output, $file) { |
|
| 281 | + $errFunc = function(RequestException $e) use ($output, $file) { |
|
| 282 | 282 | $this->errors[$file] = $e->getMessage(); |
| 283 | 283 | $output->writeln( |
| 284 | - '<error>' . str_pad( |
|
| 284 | + '<error>'.str_pad( |
|
| 285 | 285 | sprintf( |
| 286 | 286 | 'Failed to write <%s> from \'%s\' with message \'%s\'', |
| 287 | 287 | $e->getRequest()->getUri(), |
@@ -290,17 +290,17 @@ discard block |
||
| 290 | 290 | ), |
| 291 | 291 | 140, |
| 292 | 292 | ' ' |
| 293 | - ) . '</error>' |
|
| 293 | + ).'</error>' |
|
| 294 | 294 | ); |
| 295 | 295 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
| 296 | 296 | $this->dumper->dump( |
| 297 | 297 | $this->cloner->cloneVar( |
| 298 | 298 | $this->parser->parse($e->getResponse()->getBody(), false, false, true) |
| 299 | 299 | ), |
| 300 | - function ($line, $depth) use ($output) { |
|
| 300 | + function($line, $depth) use ($output) { |
|
| 301 | 301 | if ($depth > 0) { |
| 302 | 302 | $output->writeln( |
| 303 | - '<error>' . str_pad(str_repeat(' ', $depth) . $line, 140, ' ') . '</error>' |
|
| 303 | + '<error>'.str_pad(str_repeat(' ', $depth).$line, 140, ' ').'</error>' |
|
| 304 | 304 | ); |
| 305 | 305 | } |
| 306 | 306 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | 'headers'=> [] |
| 315 | 315 | ]; |
| 316 | 316 | if ($this->headerBasicAuth) { |
| 317 | - $data['headers']['Authorization'] = 'Basic '. base64_encode($this->headerBasicAuth); |
|
| 317 | + $data['headers']['Authorization'] = 'Basic '.base64_encode($this->headerBasicAuth); |
|
| 318 | 318 | } |
| 319 | 319 | if ($this->customHeaders) { |
| 320 | 320 | foreach ($this->customHeaders as $headers) { |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | // TODO This part, $uploadFile, promise should be removed once Graviton/File service is resolved in new Story. |
| 334 | 334 | $fileRepeatFunc = false; |
| 335 | 335 | if ($uploadFile) { |
| 336 | - $fileRepeatFunc = function () use ($targetUrl, $successFunc, $errFunc, $output, $file, $data) { |
|
| 336 | + $fileRepeatFunc = function() use ($targetUrl, $successFunc, $errFunc, $output, $file, $data) { |
|
| 337 | 337 | unset($this->errors[$file]); |
| 338 | 338 | $output->writeln('<info>File deleting: '.$targetUrl.'</info>'); |
| 339 | 339 | $deleteRequest = $this->client->requestAsync('DELETE', $targetUrl); |
| 340 | - $insert = function () use ($targetUrl, $successFunc, $errFunc, $output, $data) { |
|
| 340 | + $insert = function() use ($targetUrl, $successFunc, $errFunc, $output, $data) { |
|
| 341 | 341 | $output->writeln('<info>File inserting: '.$targetUrl.'</info>'); |
| 342 | 342 | $promiseInsert = $this->client->requestAsync('PUT', $targetUrl, $data); |
| 343 | 343 | $promiseInsert->then($successFunc, $errFunc); |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | // Find file |
| 410 | - $fileName = dirname($originFile) . DIRECTORY_SEPARATOR . $documentData['file']; |
|
| 410 | + $fileName = dirname($originFile).DIRECTORY_SEPARATOR.$documentData['file']; |
|
| 411 | 411 | $fileName = str_replace('//', '/', $fileName); |
| 412 | 412 | if (!file_exists($fileName)) { |
| 413 | 413 | return false; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $clientMock = $this->getMockBuilder('\MongoClient')->disableOriginalConstructor()->getMock(); |
| 52 | 52 | |
| 53 | 53 | $collectionMock = $this->getMockBuilder('\MongoCollection')->disableOriginalConstructor()->getMock(); |
| 54 | - $collectionMock->method('save')->will($this->returnCallback(array($this,'saveCollectionCallback'))); |
|
| 54 | + $collectionMock->method('save')->will($this->returnCallback(array($this, 'saveCollectionCallback'))); |
|
| 55 | 55 | |
| 56 | 56 | $dbMock = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock(); |
| 57 | 57 | $dbMock->method('selectCollection')->willReturn($collectionMock); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | // fail in output? |
| 120 | 120 | $this->assertContains( |
| 121 | - 'Could not deserialize file <' . $this->sourceDir . '/Dudess/Invalid.json>', |
|
| 121 | + 'Could not deserialize file <'.$this->sourceDir.'/Dudess/Invalid.json>', |
|
| 122 | 122 | $this->cmdTester->getDisplay() |
| 123 | 123 | ); |
| 124 | 124 | $this->assertEquals(1, $this->cmdTester->getStatusCode()); |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | $responseMock |
| 52 | 52 | ->method('getHeader') |
| 53 | 53 | ->with('Link') |
| 54 | - ->willReturn(['<' . $host . $path . '>; rel="self"']); |
|
| 54 | + ->willReturn(['<'.$host.$path.'>; rel="self"']); |
|
| 55 | 55 | |
| 56 | 56 | $promiseMock |
| 57 | 57 | ->method('then') |
| 58 | 58 | ->will( |
| 59 | 59 | $this->returnCallback( |
| 60 | - function ($ok) use ($responseMock) { |
|
| 60 | + function($ok) use ($responseMock) { |
|
| 61 | 61 | $ok($responseMock); |
| 62 | 62 | } |
| 63 | 63 | ) |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $cmdTester = $this->getTester($sut, $file); |
| 76 | 76 | |
| 77 | - $this->assertContains('Loading data from ' . $file, $cmdTester->getDisplay()); |
|
| 78 | - $this->assertContains('Wrote <' . $host . $path . '>; rel="self"', $cmdTester->getDisplay()); |
|
| 77 | + $this->assertContains('Loading data from '.$file, $cmdTester->getDisplay()); |
|
| 78 | + $this->assertContains('Wrote <'.$host.$path.'>; rel="self"', $cmdTester->getDisplay()); |
|
| 79 | 79 | $this->assertEquals(0, $cmdTester->getStatusCode()); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | return [ |
| 88 | 88 | 'basic valid file' => [ |
| 89 | 89 | 'http://localhost', |
| 90 | - __DIR__ . '/fixtures/set-01/test-2.json', |
|
| 90 | + __DIR__.'/fixtures/set-01/test-2.json', |
|
| 91 | 91 | '/core/app/test', |
| 92 | 92 | ], |
| 93 | 93 | 'basic valid image file' => [ |
| 94 | 94 | 'http://localhost', |
| 95 | - __DIR__ . '/fixtures/file', |
|
| 95 | + __DIR__.'/fixtures/file', |
|
| 96 | 96 | '/core/app/test', |
| 97 | 97 | ], |
| 98 | 98 | ]; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $requestMock = $this->createMock('Psr\Http\Message\RequestInterface'); |
| 127 | 127 | $requestMock |
| 128 | 128 | ->method('getUri') |
| 129 | - ->willReturn($host . '/core/app/test'); |
|
| 129 | + ->willReturn($host.'/core/app/test'); |
|
| 130 | 130 | |
| 131 | 131 | $exceptionMock = $this->getMockBuilder('GuzzleHttp\Exception\RequestException') |
| 132 | 132 | ->setConstructorArgs(['Client error: 400', $requestMock, $responseMock]) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | ->method('then') |
| 145 | 145 | ->will( |
| 146 | 146 | $this->returnCallback( |
| 147 | - function ($ok, $nok) use ($exceptionMock) { |
|
| 147 | + function($ok, $nok) use ($exceptionMock) { |
|
| 148 | 148 | return $nok($exceptionMock); |
| 149 | 149 | } |
| 150 | 150 | ) |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | $cmdTester = $this->getTester($sut, $file); |
| 163 | 163 | |
| 164 | - $this->assertContains('Loading data from ' . $file, $cmdTester->getDisplay()); |
|
| 164 | + $this->assertContains('Loading data from '.$file, $cmdTester->getDisplay()); |
|
| 165 | 165 | foreach ($errors as $error) { |
| 166 | 166 | $this->assertContains( |
| 167 | 167 | $error, |
@@ -179,18 +179,18 @@ discard block |
||
| 179 | 179 | return [ |
| 180 | 180 | 'invalid file (server side)' => [ |
| 181 | 181 | 'http://localhost', |
| 182 | - __DIR__ . '/fixtures/set-01/test.json', |
|
| 182 | + __DIR__.'/fixtures/set-01/test.json', |
|
| 183 | 183 | [ |
| 184 | - 'Failed to write <http://localhost/core/app/test> from \'' . |
|
| 185 | - __DIR__ . '/fixtures/set-01/test.json\' with message \'Client error: 400\'', |
|
| 184 | + 'Failed to write <http://localhost/core/app/test> from \''. |
|
| 185 | + __DIR__.'/fixtures/set-01/test.json\' with message \'Client error: 400\'', |
|
| 186 | 186 | '"message": "invalid"', |
| 187 | 187 | ], |
| 188 | 188 | ], |
| 189 | 189 | 'missing target in file (user error)' => [ |
| 190 | 190 | 'http://localhost', |
| 191 | - __DIR__ . '/fixtures/set-01/test-3.json', |
|
| 191 | + __DIR__.'/fixtures/set-01/test-3.json', |
|
| 192 | 192 | [ |
| 193 | - 'Missing target in \'' . __DIR__ . '/fixtures/set-01/test-3.json\'', |
|
| 193 | + 'Missing target in \''.__DIR__.'/fixtures/set-01/test-3.json\'', |
|
| 194 | 194 | ], |
| 195 | 195 | ] |
| 196 | 196 | ]; |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | ->method('then') |
| 233 | 233 | ->will( |
| 234 | 234 | $this->returnCallback( |
| 235 | - function ($ok) use ($responseMock) { |
|
| 235 | + function($ok) use ($responseMock) { |
|
| 236 | 236 | $ok($responseMock); |
| 237 | 237 | } |
| 238 | 238 | ) |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | $cmdTester = $this->getTester( |
| 251 | 251 | $sut, |
| 252 | - __DIR__ . '/fixtures/set-01/test-4.json', |
|
| 252 | + __DIR__.'/fixtures/set-01/test-4.json', |
|
| 253 | 253 | [ |
| 254 | 254 | 'host' => 'http://example.com', |
| 255 | 255 | '--rewrite-host' => 'http://localhost' |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @param SplFileInfo $file |
| 53 | 53 | * @return bool |
| 54 | 54 | */ |
| 55 | - $filter = function (SplFileInfo $file) { |
|
| 56 | - if (!in_array($file->getExtension(), ['yml','json']) || $file->isDir()) { |
|
| 55 | + $filter = function(SplFileInfo $file) { |
|
| 56 | + if (!in_array($file->getExtension(), ['yml', 'json']) || $file->isDir()) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | return true; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | try { |
| 74 | 74 | $exitCode = $this->doImport($finder, $input, $output); |
| 75 | 75 | } catch (MissingTargetException $e) { |
| 76 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 76 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 77 | 77 | } |
| 78 | 78 | return $exitCode; |
| 79 | 79 | } |
@@ -6,12 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | namespace Graviton\ImportExport\Command; |
| 8 | 8 | |
| 9 | -use Graviton\ImportExport\Exception\MissingTargetException; |
|
| 10 | 9 | use Symfony\Component\Console\Command\Command; |
| 11 | 10 | use Symfony\Component\Console\Helper\ProgressBar; |
| 12 | 11 | use Symfony\Component\Console\Input\InputArgument; |
| 13 | 12 | use Symfony\Component\Console\Input\InputInterface; |
| 14 | -use Symfony\Component\Console\Input\InputOption; |
|
| 15 | 13 | use Symfony\Component\Console\Output\OutputInterface; |
| 16 | 14 | use Symfony\Component\Finder\Finder; |
| 17 | 15 | use Symfony\Component\Finder\SplFileInfo; |
@@ -84,15 +84,15 @@ |
||
| 84 | 84 | protected function execute(InputInterface $input, OutputInterface $output) |
| 85 | 85 | { |
| 86 | 86 | $files = $input->getArgument('file'); |
| 87 | - $finder = new Finder(); |
|
| 87 | + $finder = new Finder(); |
|
| 88 | 88 | $finder = $finder->files(); |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * @param SplFileInfo $file |
| 92 | 92 | * @return bool |
| 93 | 93 | */ |
| 94 | - $filter = function (SplFileInfo $file) { |
|
| 95 | - if (!in_array($file->getExtension(), ['yml','json']) || $file->isDir()) { |
|
| 94 | + $filter = function(SplFileInfo $file) { |
|
| 95 | + if (!in_array($file->getExtension(), ['yml', 'json']) || $file->isDir()) { |
|
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | return true; |