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

ValidateEntity::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
}