Issues (14)

src/Meta.php (3 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\AppMeta;
6
7
use BEAR\AppMeta\Exception\AppNameException;
8
use BEAR\AppMeta\Exception\NotWritableException;
9
use ReflectionClass;
10
11
use function assert;
12
use function class_exists;
13
use function dirname;
14
use function file_exists;
15
use function is_dir;
16
use function mkdir;
17
use function sprintf;
18
19
use const DIRECTORY_SEPARATOR;
20
21
/**
22
 * @psalm-import-type AppName from Types
23
 * @psalm-import-type Context from Types
24
 * @psalm-import-type AppDir from Types
25
 */
26
final class Meta extends AbstractAppMeta
27
{
28
    /**
29
     * @param AppName $name    application name      (Vendor\Project)
0 ignored issues
show
The type BEAR\AppMeta\AppName was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     * @param Context $context application context   (prod-hal-app)
0 ignored issues
show
The type BEAR\AppMeta\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     * @param string  $appDir  application directory
32
     */
33
    public function __construct(string $name, string $context = 'app', string $appDir = '')
34
    {
35
        $this->name = $name;
36
        $this->appDir = $appDir ?: $this->getAppDir($name);
37
        $this->tmpDir = $this->appDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $context;
38
        if (! file_exists($this->tmpDir) && ! @mkdir($this->tmpDir, 0777, true) && ! is_dir($this->tmpDir)) {
39
            throw new NotWritableException($this->tmpDir);
40
        }
41
42
        $this->logDir = $this->appDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . $context;
43
        if (! file_exists($this->logDir) && ! @mkdir($this->logDir, 0777, true) && ! is_dir($this->logDir)) {
44
            throw new NotWritableException($this->logDir); // @codeCoverageIgnore
45
        }
46
    }
47
48
    /**
49
     * @param AppName $name
50
     *
51
     * @return AppDir
0 ignored issues
show
The type BEAR\AppMeta\AppDir was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
     */
53
    private function getAppDir(string $name): string
54
    {
55
        $module = $name . '\Module\AppModule';
56
        if (! class_exists($module)) {
57
            throw new AppNameException($name);
58
        }
59
60
        $fileName = (new ReflectionClass($module))->getFileName();
61
        assert($fileName !== false, sprintf('Cannot locate AppModule file: %s', $module));
62
63
        /** @var AppDir $dir */
64
        $dir = dirname($fileName, 3);
65
        assert($dir !== '.');
66
67
        return $dir;
68
    }
69
}
70