Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

Country   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 45
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getId() 0 4 1
A getCode() 0 4 1
A getName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Countries\Entity;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
10
/**
11
 * @ORM\Entity(repositoryClass="App\Countries\Repository\CountryRepository")
12
 * @ORM\Table(name="countries")
13
 * @UniqueEntity(fields="code", message="This code already exists")
14
 */
15
class Country
16
{
17
    /**
18
     * @ORM\Id()
19
     * @ORM\GeneratedValue()
20
     * @ORM\Column(type="integer")
21
     */
22
    private $id;
23
24
    /**
25
     * @ORM\Column(type="string", length=3, unique=true)
26
     */
27
    private $code;
28
29
    /**
30
     * @ORM\Column(type="string", length=50, unique=true)
31
     */
32
    private $name;
33
34
    public function __construct(string $name, string $code)
35
    {
36
        // todo movie to db constraint
37
        if (mb_strlen($code) !== 3) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
38
            // throw new \InvalidArgumentException(sprintf('"%s" should be exactly 3 characters long', $code));
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
        }
40
41
        $this->code = mb_strtoupper($code);
42
        $this->name = ucfirst($name);
43
    }
44
45
    public function getId()
46
    {
47
        return $this->id;
48
    }
49
50
    public function getCode(): string
51
    {
52
        return $this->code;
53
    }
54
55
    public function getName(): string
56
    {
57
        return $this->name;
58
    }
59
}
60