ProjectTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verifyPackageDoesntExist() 0 4 4
A verifyProjectDoesExist() 0 4 2
A verifyPackageAndProjectDoesExist() 0 4 1
A verifyPackageDoesExist() 0 4 2
1
<?php
2
3
namespace CleaniqueCoders\Console\Traits;
4
5
use CleaniqueCoders\Console\Exceptions\LaravelProjectException;
6
use CleaniqueCoders\Console\Exceptions\PackageException;
7
8
trait ProjectTrait
9
{
10
    /**
11
     * Verify Package and Project Existence.
12
     *
13
     * @param string $package Path to Package
14
     * @param string $project Path to Project
15
     */
16
    public function verifyPackageAndProjectDoesExist($package, $project)
17
    {
18
        $this->verifyProjectDoesExist($project);
19
        $this->verifyPackageDoesExist($package);
20
    }
21
22
    /**
23
     * Verify that the Laravel Project exist.
24
     *
25
     * @param string $directory
26
     */
27
    protected function verifyProjectDoesExist($directory)
28
    {
29
        if (! is_dir($directory)) {
30
            throw new LaravelProjectException('Laravel Project does not exists!');
31
        }
32
    }
33
34
    /**
35
     * Verify that the package does not already exist.
36
     *
37
     * @param string $directory
38
     */
39
    protected function verifyPackageDoesExist($directory)
40
    {
41
        if (! is_dir($directory)) {
42
            throw new LaravelProjectException('Package does not exists!');
43
        }
44
    }
45
46
    /**
47
     * Verify that the package does not already exist.
48
     *
49
     * @param string $directory
50
     */
51
    protected function verifyPackageDoesntExist($directory)
52
    {
53
        if ((is_dir($directory) || is_file($directory)) && $directory != getcwd()) {
54
            throw new PackageException('Package already exists!');
55
        }
56
    }
57
}
58