These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bankiru\Api\JsonRpc\Adapters\Symfony; |
||
| 4 | |||
| 5 | use Bankiru\Api\JsonRpc\NormalizerInterface; |
||
| 6 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface as SymfonyNormalizerInterface; |
||
| 7 | |||
| 8 | final class SymfonyNormalizerAdapter implements NormalizerInterface |
||
| 9 | { |
||
| 10 | /** @var SymfonyNormalizerInterface */ |
||
| 11 | private $normalizer; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * SymfonyNormalizerAdapter constructor. |
||
| 15 | * |
||
| 16 | * @param SymfonyNormalizerInterface $normalizer |
||
| 17 | */ |
||
| 18 | public function __construct(SymfonyNormalizerInterface $normalizer) |
||
| 19 | { |
||
| 20 | $this->normalizer = $normalizer; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** {@inheritdoc} */ |
||
| 24 | public function normalize($entity, array $context = []) |
||
| 25 | { |
||
| 26 | if (null === $entity) { |
||
| 27 | return null; |
||
| 28 | } |
||
| 29 | |||
| 30 | return $this->normalizer->normalize($entity, ['groups' => $context]); |
||
|
0 ignored issues
–
show
array('groups' => $context) is of type array<string,array,{"groups":"array"}>, but the function expects a string|null.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
The return type of
return $this->normalizer...'groups' => $context)); (array|integer|double|string|boolean) is incompatible with the return type declared by the interface Bankiru\Api\JsonRpc\NormalizerInterface::normalize of type array|null.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
|||
| 31 | } |
||
| 32 | } |
||
| 33 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.