Completed
Push — 1.x ( be14df...4f7847 )
by Akihito
10s
created

Meta::__construct()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 7.756
c 0
b 0
f 0
cc 9
eloc 12
nc 8
nop 3
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the BEAR.AppMeta package.
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 */
9
namespace BEAR\AppMeta;
10
11
use BEAR\AppMeta\Exception\AppNameException;
12
use BEAR\AppMeta\Exception\NotWritableException;
13
14
class Meta extends AbstractAppMeta
15
{
16
    /**
17
     * @param string $name    application name      (Vendor\Project)
18
     * @param string $context application context   (prod-hal-app)
19
     * @param string $appDir  application directory
20
     */
21
    public function __construct(string $name, string $context = 'app', string $appDir = '')
22
    {
23
        $this->name = $name;
24
        try {
25
            $this->appDir = $appDir ?: dirname((new \ReflectionClass($name . '\Module\AppModule'))->getFileName(), 3);
26
        } catch (\ReflectionException $e) {
27
            throw new AppNameException($name);
28
        }
29
        $this->tmpDir = $this->appDir . '/var/tmp/' . $context;
30
        if (! file_exists($this->tmpDir) && ! @mkdir($this->tmpDir, 0777, true) && ! is_dir($this->tmpDir)) {
31
            throw new NotWritableException($this->tmpDir);
32
        }
33
        $this->logDir = $this->appDir . '/var/log/' . $context;
34
        if (! file_exists($this->logDir) && ! @mkdir($this->logDir, 0777, true) && ! is_dir($this->logDir)) {
35
            throw new NotWritableException($this->logDir);
36
        }
37
    }
38
}
39