1 | <?php |
||
11 | class EntityResolver |
||
12 | { |
||
13 | const CASE_CAMEL = 'CamelCase'; |
||
14 | const CASE_UNDERSCORE = 'UnderscoreCase'; |
||
15 | |||
16 | protected $reflector; |
||
17 | protected $formater; |
||
18 | |||
19 | public function __construct(ObjectReflector $reflector, TextFormater $formater) |
||
24 | |||
25 | public function resolve(ObjectManager $entityManager, $name, $namespaces = '') |
||
26 | { |
||
27 | $results = []; |
||
28 | |||
29 | $namespaces = is_array($namespaces) ? $namespaces : [ $namespaces ]; |
||
30 | |||
31 | foreach ($namespaces as $namespace) { |
||
32 | $results = $this->getClassesFromName($entityManager, $name, $namespace, $results); |
||
33 | } |
||
34 | |||
35 | if (0 === count($results)) { |
||
36 | |||
37 | return; |
||
38 | } |
||
39 | |||
40 | return $results; |
||
41 | } |
||
42 | |||
43 | protected function getClassesFromName(ObjectManager $entityManager, $name, $namespace, array $results = []) |
||
44 | { |
||
45 | if (!empty($results)) { |
||
46 | |||
47 | return $results; |
||
48 | } |
||
49 | |||
50 | $allMetadata = $entityManager->getMetadataFactory()->getAllMetadata(); |
||
51 | $allClass = $this->reflector->getReflectionsFromMetadata($allMetadata); |
||
|
|||
52 | foreach ($this->entityNameProposal($name) as $name) { |
||
53 | $class = array_filter( |
||
54 | $allClass, |
||
55 | function ($e) use ($namespace, $name) { |
||
56 | $nameValid = strtolower($e->getShortName()) === strtolower($name); |
||
57 | |||
58 | return '' === $namespace |
||
59 | ? $nameValid |
||
60 | : $namespace === substr($e->getNamespaceName(), 0, strlen($namespace)) && $nameValid |
||
61 | ; |
||
62 | } |
||
63 | ); |
||
64 | $results = array_merge($results, $class); |
||
65 | } |
||
66 | |||
67 | return $results; |
||
68 | } |
||
69 | |||
70 | public function getMetadataFromProperty(ObjectManager $entityManager, $entity, $property) |
||
91 | |||
92 | public function getMetadataFromObject(ObjectManager $entityManager, $object) |
||
99 | |||
100 | public function entityNameProposal($name) |
||
108 | |||
109 | public function asAccessForCase($entity, $property, $case) |
||
115 | |||
116 | protected function getMappingFromMetadata(ClassMetadata $metadata, $property) |
||
126 | |||
127 | protected function getMappingFromMetadataPart($metadata, $property) |
||
142 | |||
143 | } |
||
144 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.