Issues (40)

php-src/Mapping/NullMapper.php (1 issue)

1
<?php
2
3
namespace kalanis\Restful\Mapping;
4
5
6
/**
7
 * NullMapper
8
 * @package kalanis\Restful\Mapping
9
 */
10
class NullMapper implements IMapper
11
{
12
13
    /**
14
     * Convert array or Traversable input to string output response
15
     * @param string|object|iterable<string|int, mixed> $data
16
     * @param bool $prettyPrint
17
     * @return string
18
     */
19
    public function stringify(iterable|string|object $data, bool $prettyPrint = true): string
20
    {
21
        return '';
22
    }
23
24
    /**
25
     * Convert client request data to array or traversable
26
     * @param mixed $data
27
     * @return array<string|int, mixed>
28
     */
29
    public function parse(mixed $data): array
30
    {
31
        return [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array() returns the type array which is incompatible with the return type mandated by kalanis\Restful\Mapping\IMapper::parse() of iterable|object|string.

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...
32
    }
33
}
34