Issues (121)

src/Model/Attribute/DefaultAttribute.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Attribute;
6
7
use Inspirum\Arrayable\BaseModel;
8
9
/**
10
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
11
 */
12
final class DefaultAttribute extends BaseModel implements Attribute
13
{
14 5
    public function __construct(
15
        private readonly string $name,
16
        private readonly string $dataType,
17
        private readonly ?string $maxLength,
18
    ) {
19 5
    }
20
21 2
    public function getName(): string
22
    {
23 2
        return $this->name;
24
    }
25
26 1
    public function getDataType(): string
27
    {
28 1
        return $this->dataType;
29
    }
30
31 1
    public function getMaxLength(): ?string
32
    {
33 1
        return $this->maxLength;
34
    }
35
36
    /** @inheritDoc */
37 2
    public function __toArray(): array
38
    {
39 2
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('name' => $...h' => $this->maxLength) returns the type array<string,null|string> which is incompatible with the return type mandated by Inspirum\Arrayable\BaseModel::__toArray() of Inspirum\Arrayable\TValue[].

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...
40 2
            'name' => $this->name,
41 2
            'dataType' => $this->dataType,
42 2
            'maxLength' => $this->maxLength,
43 2
        ];
44
    }
45
}
46