ProjectTrait::verifyPackageAndProjectDoesExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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