ExportCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ParseServerMigration\Console\Command;
4
5
use ParseServerMigration\Config;
6
use ParseServerMigration\Console\PictureApplicationService;
7
use ParseServerMigration\Console\PictureRepository;
8
use Parse\ParseQuery;
9
use Psr\Log\LoggerInterface;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
/**
16
 * @author Maxence Dupressoir <[email protected]>
17
 * @copyright 2016 Meetic
18
 */
19
class ExportCommand extends Command
20
{
21
    /**
22
     * @var PictureRepository
23
     */
24
    private $pictureApplicationService;
25
26
    /**
27
     * @var LoggerInterface
28
     */
29
    private $logger;
30
31
    /**
32
     * @param PictureApplicationService $pictureApplicationService
33
     * @param LoggerInterface           $logger
34
     */
35 1
    public function __construct(PictureApplicationService $pictureApplicationService, LoggerInterface $logger)
36
    {
37 1
        $this->pictureApplicationService = $pictureApplicationService;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pictureApplicationService of type object<ParseServerMigrat...tureApplicationService> is incompatible with the declared type object<ParseServerMigrat...sole\PictureRepository> of property $pictureApplicationService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38 1
        $this->logger = $logger;
39 1
        parent::__construct();
40 1
    }
41
42 1
    protected function configure()
43
    {
44
        $this
45 1
            ->setName('parse:migration:export')
46 1
            ->setDescription('Upload existing parse pictures to S3 bucket and rename')
47
        ;
48 1
    }
49
50 1
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52 1
        $io = new SymfonyStyle($input, $output);
53 1
        $io->title('Parse migration tool');
54 1
        $io->section('Export command');
55 1
        $io->text('Upload existing parse pictures to S3 bucket and rename file in mongoDB');
56
57 1
        $limit = $io->ask('Number of picture to export', 1, null);
58 1
        $descOrder = $io->confirm('Migrate newer pictures first ?', false);
59
60
        //Because we have 2 steps for each picture
61 1
        $io->progressStart($limit * 2);
62 1
        $io->newLine();
63
64 1
        $pictures = $this->pictureApplicationService->retrievePictures($limit, $descOrder);
0 ignored issues
show
Bug introduced by
The method retrievePictures() does not seem to exist on object<ParseServerMigrat...sole\PictureRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
66 1
        foreach ($pictures as $picture) {
67
            try {
68
                $io->text('Migrating picture\'s image');
69
                $message = $this->pictureApplicationService->migrateImage($picture);
0 ignored issues
show
Bug introduced by
The method migrateImage() does not seem to exist on object<ParseServerMigrat...sole\PictureRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
                $io->progressAdvance(1);
71
                $io->newLine();
72
                $this->logger->info($message);
73
                $io->success($message);
74
75
                $io->text('Migrating picture\'s thumbnail');
76
                $message = $this->pictureApplicationService->migrateThumbnail($picture);
0 ignored issues
show
Bug introduced by
The method migrateThumbnail() does not seem to exist on object<ParseServerMigrat...sole\PictureRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
                $io->progressAdvance(1);
78
                $io->newLine();
79
                $this->logger->info($message);
80
                $io->success($message);
81
            } catch (\ErrorException $exception) {
82
                $message = 'Upload failed for: ['.$picture->get(Config::PARSE_FILES_FIELD_NAME)->getName().'] \nDetail error : ['.$exception->getMessage().']';
83
84
                $this->logger->error($message);
85
                $io->warning($message);
86
            }
87
        }
88 1
    }
89
}
90