Completed
Push — develop ( d8ba64...7d836d )
by Mohamed
08:56
created

Role::className()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 10
cts 11
cp 0.9091
rs 8.8571
cc 5
eloc 11
nc 5
nop 0
crap 5.0187
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model;
13
14
use Illuminate\Database\Eloquent\Model;
15
use Tinyissue\Model\Project\User;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Tinyissue\Model\User.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
17
/**
18
 * Role is model class for roles.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @property int $id
23
 * @property string $name
24
 * @property string $role
25
 * @property string $description
26
 * @property \Tinyissue\Model\User[] $users
27
 * @property User[] $projectUsers
28
 * @property Permission[] $permissions
29
 */
30
class Role extends Model
31
{
32
    use Traits\Role\QueryTrait,
33
        Traits\Role\RelationTrait;
34
35
    const ROLE_USER      = 'user';
36
    const ROLE_DEVELOPER = 'developer';
37
    const ROLE_MANAGER   = 'manager';
38
    const ROLE_ADMIN     = 'administrator';
39
40
    /**
41
     * Timestamp enabled.
42
     *
43
     * @var bool
44
     */
45
    public $timestamps = false;
46
47
    /**
48
     * Name of database table.
49
     *
50
     * @var string
51
     */
52
    protected $table = 'roles';
53
54
    /**
55
     * Returns a class name based on role type.
56
     *
57
     * @return string
58
     */
59 4
    public function className()
60
    {
61 4
        switch (strtolower($this->name)) {
62 4
            case self::ROLE_USER:
63 1
                return 'tag';
64 4
            case self::ROLE_MANAGER:
65 1
                return 'success';
66 4
            case self::ROLE_DEVELOPER:
67 4
                return 'info';
68 1
            case self::ROLE_ADMIN:
69 1
                return 'primary';
70
        }
71
72
        return 'primary';
73
    }
74
}
75