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

Meta   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 17 9
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