Application::isPharContextAllowed()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sugarcrm\UpgradeSpec;
4
5
use Sugarcrm\UpgradeSpec\Command\PharContext;
6
use Symfony\Component\Console\Application as BaseApplication;
7
use Symfony\Component\Console\Command\Command;
8
9
final class Application extends BaseApplication
10
{
11
    /**
12
     * Gets full version name.
13
     *
14
     * @return string
15
     */
16
    public function getLongVersion()
17
    {
18
        $art = <<<EOL
19
      ___            ___            ___          ___            ___     
20
     /__/\          /  /\          /  /\        /  /\          /  /\    
21
     \  \:\        /  /:/_        /  /::\      /  /:/_        /  /:/    
22
      \  \:\      /  /:/ /\      /  /:/\:\    /  /:/ /\      /  /:/     
23
  ___  \  \:\    /  /:/ /::\    /  /:/~/:/   /  /:/ /:/_    /  /:/  ___ 
24
 /__/\  \__\:\  /__/:/ /:/\:\  /__/:/ /:/   /__/:/ /:/ /\  /__/:/  /  /\
25
 \  \:\ /  /:/  \  \:\/:/~/:/  \  \:\/:/    \  \:\/:/ /:/  \  \:\ /  /:/
26
  \  \:\  /:/    \  \::/ /:/    \  \::/      \  \::/ /:/    \  \:\  /:/ 
27
   \  \:\/:/      \__\/ /:/      \  \:\       \  \:\/:/      \  \:\/:/  
28
    \  \::/         /__/:/        \  \:\       \  \::/        \  \::/   
29
     \__\/          \__\/          \__\/        \__\/          \__\/    
30
EOL;
31
32
        return sprintf('<info>%s</info>', $art) . PHP_EOL . PHP_EOL . parent::getLongVersion() . ' by <comment>Mike Kamornikov</comment> and <comment>Denis Stiblo</comment>';
33
    }
34
35
    public function add(Command $command)
36
    {
37
        if (($command instanceof PharContext) && !$this->isPharContextAllowed()) {
38
            return null;
39
        }
40
41
        return parent::add($command);
42
    }
43
44
    /**
45
     * Defines if it's called from phar.
46
     *
47
     * @return bool
48
     */
49
    private function isPharContextAllowed()
50
    {
51
        return \Phar::running() || (bool) getenv('DEV_MODE');
52
    }
53
}
54