ProjectFinder::keyIsUnique()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Model\Finder;
4
5
use App\Model\Project;
6
use Ronanchilvers\Orm\Finder;
7
use ClanCats\Hydrahon\Query\Expression;
8
9
/**
10
 * Finder for project models
11
 *
12
 * @author Ronan Chilvers <[email protected]>
13
 */
14
class ProjectFinder extends Finder
15
{
16
    /**
17
     * Get a list of all projects ordered by project name
18
     *
19
     * @return array
20
     * @author Ronan Chilvers <[email protected]>
21
     */
22
    public function all(array $ids = null)
23
    {
24
        $select = $this->select()
25
            ->orderBy(Project::prefix('last_deployment'), 'desc')
26
            ->orderBy(Project::prefix('repository'), 'asc')
27
            ;
28
        if (is_array($ids)) {
29
            $select->where(Project::primaryKey(), 'IN', $ids);
30
        }
31
        return $select->execute();
32
    }
33
34
    /**
35
     * Get a project by project key
36
     *
37
     * @param string $key
38
     * @return \App\Model\Project
39
     * @author Ronan Chilvers <[email protected]>
40
     */
41
    public function forKey($key)
42
    {
43
        return $this->select()
44
            ->where(Project::prefix('key'), $key)
45
            ->one();
46
    }
47
48
    /**
49
     * Get a project by project token
50
     *
51
     * @param string $token
52
     * @return \App\Model\Project
53
     * @author Ronan Chilvers <[email protected]>
54
     */
55
    public function forToken($token)
56
    {
57
        return $this->select()
58
            ->where(Project::prefix('token'), $token)
59
            ->one();
60
    }
61
62
    /**
63
     * Check that a given key is unique
64
     *
65
     * @param string $key
66
     * @return boolean
67
     * @author Ronan Chilvers <[email protected]>
68
     */
69
    public function keyIsUnique($key)
70
    {
71
        $existing = $this->select()
72
            ->where(Project::prefix('key'), $key)
73
            ->one();
74
75
        return !$existing instanceof Project;
76
    }
77
}
78