Completed
Push — develop ( 8fda15...dbbcf5 )
by Jaap
14s
created

Application   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 10%

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 2
cts 20
cp 0.1
rs 10
c 0
b 0
f 0
wmc 13
lcom 0
cbo 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A VERSION() 0 4 1
A __construct() 0 20 1
B defineIniSettings() 0 21 7
A setTimezone() 0 8 4
1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor;
13
14
use Cilex\Application as Cilex;
15
use phpDocumentor\Event\Dispatcher;
16
use phpDocumentor\Event\LogEvent;
17
use phpDocumentor\Parser\Event\PreFileEvent;
18
use phpDocumentor\Translator\Translator;
19
use Psr\Container\ContainerInterface;
20
use Psr\Log\LoggerInterface;
21
use Psr\Log\LogLevel;
22
23
/**
24
 * Application class for phpDocumentor.
25
 *
26
 * Can be used as bootstrap when the run method is not invoked.
27
 */
28
class Application extends Cilex
29
{
30 1
    public static function VERSION()
31
    {
32 1
        return trim(file_get_contents(__DIR__ . '/../../VERSION'));
33
    }
34
35
    /**
36
     * Initializes all components used by phpDocumentor.
37
     */
38
    public function __construct(LoggerInterface $logger, Translator $translator, ContainerInterface $container)
39
    {
40
        parent::__construct($container);
0 ignored issues
show
Compatibility introduced by
$container of type object<Psr\Container\ContainerInterface> is not a sub-type of object<Symfony\Component...ion\ContainerInterface>. It seems like you assume a child interface of the interface Psr\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
41
42
        $this->defineIniSettings();
43
        $this->register(new Plugin\ServiceProvider());
44
45
        Dispatcher::getInstance()->addListener(
46
            'parser.file.pre',
47
            function (PreFileEvent $event) use ($logger) {
48
                $logger->log(LogLevel::INFO, 'Parsing ' . $event->getFile());
49
            }
50
        );
51
52
        Dispatcher::getInstance()->addListener('system.log', function (LogEvent $e) use ($logger, $translator) {
53
            $logger->log($e->getPriority(), $translator->translate($e->getMessage()), $e->getContext());
54
        });
55
56
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type object<Psr\Container\ContainerInterface>, but the property $container was declared to be of type object<Symfony\Component...ion\ContainerInterface>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
57
    }
58
59
    /**
60
     * Adjust php.ini settings.
61
     */
62
    protected function defineIniSettings()
63
    {
64
        $this->setTimezone();
65
        ini_set('memory_limit', -1);
66
67
        // this code cannot be tested because we cannot control the system settings in unit tests
68
        // @codeCoverageIgnoreStart
69
        if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) {
70
            if (ini_get('opcache.save_comments')) {
71
                ini_set('opcache.load_comments', 1);
72
            } else {
73
                ini_set('opcache.enable', 0);
74
            }
75
        }
76
77
        if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of ini_get('zend_optimizerplus.save_comments') (string) and 0 (integer) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
78
            throw new \RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.');
79
        }
80
81
        // @codeCoverageIgnoreEnd
82
    }
83
84
    /**
85
     * If the timezone is not set anywhere, set it to UTC.
86
     *
87
     * This is done to prevent any warnings being outputted in relation to using
88
     * date/time functions. What is checked is php.ini, and if the PHP version
89
     * is prior to 5.4, the TZ environment variable.
90
     *
91
     * @link http://php.net/manual/en/function.date-default-timezone-get.php for more information how PHP determines the
92
     *     default timezone.
93
     *
94
     * @codeCoverageIgnore this method is very hard, if not impossible, to unit test and not critical.
95
     */
96
    protected function setTimezone()
97
    {
98
        if (false === ini_get('date.timezone')
99
            || (version_compare(PHP_VERSION, '5.4.0', '<') && false === getenv('TZ'))
100
        ) {
101
            date_default_timezone_set('UTC');
102
        }
103
    }
104
}
105