Passed
Push — master ( d360bf...a5db3c )
by Anton
01:29
created

ValidateEntities   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 6 3
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 ValidateEntities 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
}