Completed
Push — develop ( 0b8425...c51867 )
by Jaap
15s queued 11s
created

src/phpDocumentor/Application.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor;
17
18
use Cilex\Application as Cilex;
19
use phpDocumentor\Event\Dispatcher;
20
use phpDocumentor\Parser\Event\PreFileEvent;
21
use Psr\Container\ContainerInterface;
22
use Psr\Log\LoggerInterface;
23
use Psr\Log\LogLevel;
24
use RuntimeException;
25
26
/**
27
 * Application class for phpDocumentor.
28
 *
29
 * Can be used as bootstrap when the run method is not invoked.
30
 *
31
 * @codeCoverageIgnore too many side-effects and system calls to properly test
32
 */
33
class Application extends Cilex
34
{
35
    public static function VERSION(): string
36
    {
37
        return trim(file_get_contents(__DIR__ . '/../../VERSION'));
38
    }
39
40
    public static function templateDirectory(): string
41
    {
42
        $templateDir = __DIR__ . '/../../data/templates';
43
44
        // when installed using composer the templates are in a different folder
45
        $composerTemplatePath = __DIR__ . '/../../../templates';
46
        if (file_exists($composerTemplatePath)) {
47
            $templateDir = $composerTemplatePath;
48
        }
49
50
        return $templateDir;
51
    }
52
53
    /**
54
     * Initializes all components used by phpDocumentor.
55
     */
56
    public function __construct(LoggerInterface $logger, ContainerInterface $container)
57
    {
58
        parent::__construct($container);
0 ignored issues
show
$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...
59
60
        $this->defineIniSettings();
61
        $this->register(new Plugin\ServiceProvider());
62
63
        Dispatcher::getInstance()->addListener(
64
            'parser.file.pre',
65
            function (PreFileEvent $event) use ($logger) {
66
                $logger->log(LogLevel::NOTICE, 'Parsing ' . $event->getFile());
67
            }
68
        );
69
70
        $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...
71
    }
72
73
    /**
74
     * Adjust php.ini settings.
75
     *
76
     * @throws RuntimeException
77
     */
78
    protected function defineIniSettings(): void
79
    {
80
        $this->setTimezone();
81
        ini_set('memory_limit', '-1');
82
83
        if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) {
84
            if (ini_get('opcache.save_comments')) {
85
                ini_set('opcache.load_comments', '1');
86
            } else {
87
                ini_set('opcache.enable', '0');
88
            }
89
        }
90
91
        if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) {
92
            throw new RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.');
93
        }
94
    }
95
96
    /**
97
     * If the timezone is not set anywhere, set it to UTC.
98
     *
99
     * This is done to prevent any warnings being outputted in relation to using
100
     * date/time functions.
101
     *
102
     * @link http://php.net/manual/en/function.date-default-timezone-get.php for more information how PHP determines the
103
     *     default timezone.
104
     */
105
    protected function setTimezone(): void
106
    {
107
        if (false === ini_get('date.timezone')) {
108
            date_default_timezone_set('UTC');
109
        }
110
    }
111
}
112