ensureSuccessfulOpcacheCall()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 8.304

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 9
nc 5
nop 1
dl 0
loc 16
ccs 6
cts 10
cp 0.6
crap 8.304
rs 9.2222
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
abstract class AbstractOpcacheCommand extends AbstractCommand
19
{
20
    /**
21
     * @param array $info
22
     */
23 2
    protected function ensureSuccessfulOpcacheCall($info)
24
    {
25 2
        if ($info === false) {
0 ignored issues
show
introduced by
The condition $info === false is always false.
Loading history...
26
           throw new \RuntimeException('opcache_get_status(): No Opcache status info available.  Perhaps Opcache is disabled via opcache.enable or opcache.enable_cli?');
27
        }
28
29 2
        if ($info['restart_pending'] ?? false) {
30
            $cacheStatus = $info['cache_full'] ? 'Also, you cache is full.' : '';
31
            throw new \RuntimeException("OPCache is restart, as such files can't be invalidated. Try again later. ${cacheStatus}");
32
        }
33
34 2
        $file_cache_only = $info['file_cache_only'] ?? false;
35 2
        $opcache_enabled = $info['opcache_enabled'] ?? false;
36
37 2
        if (!$opcache_enabled && $file_cache_only) {
38
            throw new \RuntimeException("Couldn't execute command because opcache is only functioning as a file cache. Set `opcache.file_cache_only` to false if you want to use this command. Read more at https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.file-cache-only");
39
        }
40 2
    }
41
}
42