Passed
Push — master ( 011363...d360bf )
by Anton
01:35
created

src/Generator/ValidateEntity.php (1 issue)

1
<?php declare(strict_types=1);
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Cycle\Schema\Generator;
10
11
use Cycle\Schema\Exception\EntityException;
12
use Cycle\Schema\GeneratorInterface;
13
use Cycle\Schema\Registry;
14
15
final class ValidateEntity implements GeneratorInterface
16
{
17
    /**
18
     * @param Registry $registry
19
     * @return Registry
20
     *
21
     * @throws EntityException
22
     */
23
    public function run(Registry $registry): Registry
24
    {
25
        foreach ($registry->getIterator() as $entity) {
26
            if (count($entity->getFields()) === 0) {
27
                throw new EntityException(
28
                    "Entity `{$entity->getRole()}` is empty"
29
                );
30
            }
31
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Cycle\Schema\Registry. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
32
    }
33
}