Passed
Pull Request — master (#19)
by
unknown
02:18
created

PrimaryKey::getColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated\Annotation\Table;
6
7
use Doctrine\Common\Annotations\Annotation\Attribute;
8
use Doctrine\Common\Annotations\Annotation\Attributes;
9
use Doctrine\Common\Annotations\Annotation\Target;
10
11
/**
12
 * @Annotation
13
 * @Target("ANNOTATION", "CLASS")
14
 * @Attributes({
15
 *      @Attribute("columns", type="array<string>", required=true),
16
 * })
17
 */
18
#[\Attribute(\Attribute::TARGET_CLASS)]
19
class PrimaryKey extends Index
20
{
21
    /** @var string[] */
22
    private $columns = [];
23
24
    public function __construct(array $values)
25
    {
26
        foreach ($values as $key => $value) {
27
            $this->$key = $value;
28
        }
29
    }
30
31
    /**
32
     * @return string[]
33
     */
34
    public function getColumns(): array
35
    {
36
        return $this->columns;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->columns returns the type string[] which is incompatible with the return type mandated by Cycle\Annotated\Annotati...ble\Index::getColumns() of Cycle\Annotated\Annotation\Column[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
37
    }
38
}
39