Code Duplication    Length = 43-44 lines in 2 locations

src/Command/ConvertCommand.php 1 location

@@ 66-108 (lines=43) @@
63
     *
64
     * @return int
65
     */
66
    protected function execute(InputInterface $input, OutputInterface $output) : int
67
    {
68
        $logger = LoggerHelper::createDefaultLogger($output);
69
70
        /** @var string $cacheOption */
71
        $cacheOption = $input->getOption('cache');
72
        $fileCache = new FilesystemCache($cacheOption);
73
        $cache = new SimpleCacheAdapter($fileCache);
74
75
        $logger->info('initializing converting process');
76
77
        $browscap = new BrowscapUpdater($cache, $logger);
78
79
        $logger->info('started converting local file');
80
81
        /** @var string $file */
82
        $file = $input->getArgument('file');
83
        if (! $file) {
84
            $file = $this->defaultIniFile;
85
        }
86
87
        $output->writeln(sprintf('converting file %s', $file));
88
89
        try {
90
            $browscap->convertFile($file);
91
        } catch (Exception\FileNameMissingException $e) {
92
            $logger->debug($e);
93
94
            return 6;
95
        } catch (Exception\FileNotFoundException $e) {
96
            $logger->debug($e);
97
98
            return 7;
99
        } catch (Exception\ErrorReadingFileException $e) {
100
            $logger->debug($e);
101
102
            return 8;
103
        }
104
105
        $logger->info('finished converting local file');
106
107
        return 0;
108
    }
109
}
110

src/Command/FetchCommand.php 1 location

@@ 77-120 (lines=44) @@
74
     *
75
     * @return int
76
     */
77
    protected function execute(InputInterface $input, OutputInterface $output) : int
78
    {
79
        $logger = LoggerHelper::createDefaultLogger($output);
80
81
        /** @var string $cacheOption */
82
        $cacheOption = $input->getOption('cache');
83
        $fileCache = new FilesystemCache($cacheOption);
84
        $cache = new SimpleCacheAdapter($fileCache);
85
86
        /** @var string $file */
87
        $file = $input->getArgument('file');
88
        if (! $file) {
89
            $file = $this->defaultIniFile;
90
        }
91
92
        $output->writeln(sprintf('write fetched file to %s', $file));
93
94
        $logger->info('started fetching remote file');
95
96
        $browscap = new BrowscapUpdater($cache, $logger);
97
98
        /** @var string $remoteFileOption */
99
        $remoteFileOption = $input->getOption('remote-file');
100
101
        try {
102
            $browscap->fetch($file, $remoteFileOption);
103
        } catch (ErrorCachedVersionException $e) {
104
            $logger->debug($e);
105
106
            return 3;
107
        } catch (FetcherException $e) {
108
            $logger->debug($e);
109
110
            return 9;
111
        } catch (Exception $e) {
112
            $logger->debug($e);
113
114
            return 10;
115
        }
116
117
        $logger->info('finished fetching remote file');
118
119
        return 0;
120
    }
121
}
122