1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace BrowscapPHP\Command; |
5
|
|
|
|
6
|
|
|
use BrowscapPHP\BrowscapUpdater; |
7
|
|
|
use BrowscapPHP\Helper\LoggerHelper; |
8
|
|
|
use Doctrine\Common\Cache\FilesystemCache; |
9
|
|
|
use Roave\DoctrineSimpleCache\SimpleCacheAdapter; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Command to fetch a browscap ini file from the remote host, convert it into an array and store the content in a local |
17
|
|
|
* file |
18
|
|
|
*/ |
19
|
|
|
class CheckUpdateCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $defaultCacheFolder; |
25
|
|
|
|
26
|
|
|
public function __construct(string $defaultCacheFolder) |
27
|
|
|
{ |
28
|
|
|
$this->defaultCacheFolder = $defaultCacheFolder; |
29
|
|
|
|
30
|
|
|
parent::__construct(); |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
protected function configure() : void |
34
|
|
|
{ |
35
|
|
|
$this |
36
|
1 |
|
->setName('browscap:check-update') |
37
|
1 |
|
->setDescription('Checks if an updated INI file is available.') |
38
|
1 |
|
->addOption( |
39
|
1 |
|
'cache', |
40
|
1 |
|
'c', |
41
|
1 |
|
InputOption::VALUE_OPTIONAL, |
42
|
1 |
|
'Where the cache files are located', |
43
|
1 |
|
$this->defaultCacheFolder |
44
|
|
|
); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
protected function execute(InputInterface $input, OutputInterface $output) : void |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$logger = LoggerHelper::createDefaultLogger($output); |
50
|
|
|
|
51
|
|
|
$fileCache = new FilesystemCache($input->getOption('cache')); |
52
|
|
|
$cache = new SimpleCacheAdapter($fileCache); |
53
|
|
|
|
54
|
|
|
$logger->debug('started checking for new version of remote file'); |
55
|
|
|
|
56
|
|
|
$browscap = new BrowscapUpdater($cache, $logger); |
57
|
|
|
$browscap->checkUpdate(); |
58
|
|
|
|
59
|
|
|
$logger->debug('finished checking for new version of remote file'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.