@@ -129,10 +129,10 @@ |
||
129 | 129 | public function newEntity(array $data): EntityInterface |
130 | 130 | { |
131 | 131 | $entity = $this->getHydrator() |
132 | - ->hydrate(array_merge( |
|
133 | - $this->getConfig()->getAttributeDefaults(), |
|
134 | - $data |
|
135 | - )); |
|
132 | + ->hydrate(array_merge( |
|
133 | + $this->getConfig()->getAttributeDefaults(), |
|
134 | + $data |
|
135 | + )); |
|
136 | 136 | |
137 | 137 | return $this->behaviours->apply($this, __FUNCTION__, $entity); |
138 | 138 | } |
@@ -172,7 +172,7 @@ |
||
172 | 172 | |
173 | 173 | public function getRelation(string $name): Relation |
174 | 174 | { |
175 | - if (! $this->hasRelation($name)) { |
|
175 | + if (!$this->hasRelation($name)) { |
|
176 | 176 | throw new \InvalidArgumentException("Relation named {$name} is not registered for this mapper"); |
177 | 177 | } |
178 | 178 |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | $setter = $class->addMethod(Str::methodName($name . ' Attribute', 'set')); |
58 | 58 | $setter->setVisibility(ClassType::VISIBILITY_PROTECTED); |
59 | 59 | $setter->addParameter('value') |
60 | - ->setNullable($this->property->getNullable()) |
|
61 | - ->setType($alias); |
|
60 | + ->setNullable($this->property->getNullable()) |
|
61 | + ->setType($alias); |
|
62 | 62 | $setter->setBody($body); |
63 | 63 | $setter->setComment($this->property->getSetterComment()); |
64 | 64 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | $setter = $class->addMethod(Str::methodName($name, 'set')); |
77 | 77 | $setter->setVisibility(ClassType::VISIBILITY_PUBLIC); |
78 | 78 | $setter->addParameter('value') |
79 | - ->setType($type) |
|
80 | - ->setNullable($this->property->getNullable()); |
|
79 | + ->setType($type) |
|
80 | + ->setNullable($this->property->getNullable()); |
|
81 | 81 | $setter->setBody($body); |
82 | 82 | $setter->setComment($this->property->getSetterComment()); |
83 | 83 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $name = $this->relation->getName(); |
55 | 55 | $foreignMapper = $mapper->getOrm()->getMapper($this->relation->getForeignMapper()); |
56 | 56 | $type = $foreignMapper->getEntityNamespace() |
57 | - . '\\' . $foreignMapper->getEntityClass(); |
|
57 | + . '\\' . $foreignMapper->getEntityClass(); |
|
58 | 58 | |
59 | 59 | $class->getNamespace()->addUse(Collection::class); |
60 | 60 | $class->getNamespace()->addUse($type, null, $type); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $setter = $class->addMethod(Str::methodName($name, 'set')); |
66 | 66 | $setter->setVisibility(ClassType::VISIBILITY_PUBLIC); |
67 | 67 | $setter->addParameter('value') |
68 | - ->setType('Collection'); |
|
68 | + ->setType('Collection'); |
|
69 | 69 | $setter->setBody('$this->set(\'' . $name . '\', $value);'); |
70 | 70 | |
71 | 71 | $getter = $class->addMethod(Str::methodName($name, 'get')); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $adder = $class->addMethod(Str::methodName($singular, 'add')); |
80 | 80 | $adder->setVisibility(ClassType::VISIBILITY_PUBLIC); |
81 | 81 | $adder->addParameter($singular) |
82 | - ->setType($type); |
|
82 | + ->setType($type); |
|
83 | 83 | $adder->setBody(sprintf('$this->get(\'%s\')->add($%s);', $name, $singular)); |
84 | 84 | |
85 | 85 | $class = $this->addAggregates($class); |
@@ -104,7 +104,7 @@ |
||
104 | 104 | |
105 | 105 | private function addAggregates(ClassType $class) |
106 | 106 | { |
107 | - $mapper = $this->relation->getMapper(); |
|
107 | + $mapper = $this->relation->getMapper(); |
|
108 | 108 | $aggregates = $this->relation->getAggregates(); |
109 | 109 | |
110 | 110 | foreach ($aggregates as $name => $aggregate) { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | protected function ensureHydratedElement($element) |
42 | 42 | { |
43 | - if (! $this->hydrator) { |
|
43 | + if (!$this->hydrator) { |
|
44 | 44 | return $element; |
45 | 45 | } |
46 | 46 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function add($element) |
79 | 79 | { |
80 | 80 | $element = $this->ensureHydratedElement($element); |
81 | - if (! $this->contains($element)) { |
|
81 | + if (!$this->contains($element)) { |
|
82 | 82 | $this->change('added', $element); |
83 | 83 | |
84 | 84 | return $this->collection->add($element); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | public function removeElement($element) |
103 | 103 | { |
104 | 104 | $element = $this->ensureHydratedElement($element); |
105 | - if (! $this->contains($element)) { |
|
105 | + if (!$this->contains($element)) { |
|
106 | 106 | return true; |
107 | 107 | } |
108 | 108 | $removed = $this->collection->removeElement($this->findByPk($this->hydrator->getPk($element))); |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | |
128 | 128 | public function pluck($names) |
129 | 129 | { |
130 | - return $this->map(function ($item) use ($names) { |
|
131 | - if (! is_array($names)) { |
|
130 | + return $this->map(function($item) use ($names) { |
|
131 | + if (!is_array($names)) { |
|
132 | 132 | return $this->hydrator->get($item, $names); |
133 | 133 | } |
134 | 134 |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | return [ |
73 | 73 | 'path' => $mapper->getDestination() . $class->getName() . '.php', |
74 | 74 | 'contents' => $this->classPrinter->printFile($file) |
75 | - . PHP_EOL |
|
76 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
77 | - . $this->classPrinter->printClass($class) |
|
75 | + . PHP_EOL |
|
76 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
77 | + . $this->classPrinter->printClass($class) |
|
78 | 78 | ]; |
79 | 79 | } |
80 | 80 | |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | return [ |
94 | 94 | 'path' => $mapper->getDestination() . $class->getName() . '.php', |
95 | 95 | 'contents' => $this->classPrinter->printFile($file) |
96 | - . PHP_EOL |
|
97 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
98 | - . $this->classPrinter->printClass($class) |
|
96 | + . PHP_EOL |
|
97 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
98 | + . $this->classPrinter->printClass($class) |
|
99 | 99 | ]; |
100 | 100 | } |
101 | 101 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | return [ |
110 | 110 | 'path' => $mapper->getDestination() . $class->getName() . '.php', |
111 | 111 | 'contents' => $this->classPrinter->printFile($file) |
112 | - . PHP_EOL |
|
113 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
114 | - . $this->classPrinter->printClass($class) |
|
112 | + . PHP_EOL |
|
113 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
114 | + . $this->classPrinter->printClass($class) |
|
115 | 115 | ]; |
116 | 116 | } |
117 | 117 | |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | return [ |
132 | 132 | 'path' => $mapper->getDestination() . $class->getName() . '.php', |
133 | 133 | 'contents' => $this->classPrinter->printFile($file) |
134 | - . PHP_EOL |
|
135 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
136 | - . $this->classPrinter->printClass($class) |
|
134 | + . PHP_EOL |
|
135 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
136 | + . $this->classPrinter->printClass($class) |
|
137 | 137 | ]; |
138 | 138 | } |
139 | 139 | |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | return [ |
148 | 148 | 'path' => $mapper->getEntityDestination() . $class->getName() . '.php', |
149 | 149 | 'contents' => $this->classPrinter->printFile($file) |
150 | - . PHP_EOL |
|
151 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
152 | - . $this->classPrinter->printClass($class) |
|
150 | + . PHP_EOL |
|
151 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
152 | + . $this->classPrinter->printClass($class) |
|
153 | 153 | ]; |
154 | 154 | } |
155 | 155 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | return [ |
170 | 170 | 'path' => $mapper->getEntityDestination() . $class->getName() . '.php', |
171 | 171 | 'contents' => $this->classPrinter->printFile($file) |
172 | - . PHP_EOL |
|
173 | - . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
174 | - . $this->classPrinter->printClass($class) |
|
172 | + . PHP_EOL |
|
173 | + . ($class->getNamespace() ? $this->classPrinter->printNamespace($class->getNamespace()) : '') |
|
174 | + . $this->classPrinter->printClass($class) |
|
175 | 175 | ]; |
176 | 176 | } |
177 | 177 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | { |
143 | 143 | $this->namespace->addUse($this->mapper->getEntityNamespace() . '\\' . $this->mapper->getEntityClass()); |
144 | 144 | $method = $this->class->addMethod('find') |
145 | - ->setReturnNullable(true) |
|
146 | - ->setReturnType($this->mapper->getEntityClass()); |
|
145 | + ->setReturnNullable(true) |
|
146 | + ->setReturnType($this->mapper->getEntityClass()); |
|
147 | 147 | $method->addParameter('pk'); |
148 | 148 | $method->addParameter('load', [])->setType('array'); |
149 | 149 | $method->setBody('return $this->newQuery()->find($pk, $load);'); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | protected function addNewQueryMethod() |
153 | 153 | { |
154 | 154 | $method = $this->class->addMethod('newQuery') |
155 | - ->setReturnType($this->mapper->getQueryClass()); |
|
155 | + ->setReturnType($this->mapper->getQueryClass()); |
|
156 | 156 | $method->addBody(sprintf('$query = new %s($this->getReadConnection(), $this);', $this->mapper->getQueryClass())); |
157 | 157 | $method->addBody('return $this->behaviours->apply($this, __FUNCTION__, $query);'); |
158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $this->namespace->addUse(StateEnum::class); |
165 | 165 | |
166 | 166 | $method = $this->class->addMethod('save') |
167 | - ->setReturnType('bool'); |
|
167 | + ->setReturnType('bool'); |
|
168 | 168 | $method->addParameter('entity')->setType($this->mapper->getEntityClass()); |
169 | 169 | $method->addParameter('withRelations', false); |
170 | 170 | $method->setBody(' |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | protected function addDeleteMethod() |
203 | 203 | { |
204 | 204 | $method = $this->class->addMethod('delete') |
205 | - ->setReturnType('bool'); |
|
205 | + ->setReturnType('bool'); |
|
206 | 206 | $method->addParameter('entity')->setType($this->mapper->getEntityClass()); |
207 | 207 | $method->addParameter('withRelations', false); |
208 | 208 | $method->setBody(' |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | public function observeBaseMapperClass(ClassType $class): ClassType |
48 | 48 | { |
49 | 49 | $class->addProperty('createdAtColumn', $this->behaviour->getCreatedAtColumn()) |
50 | - ->setVisibility('protected'); |
|
50 | + ->setVisibility('protected'); |
|
51 | 51 | $class->addProperty('updatedAtColumn', $this->behaviour->getUpdatedAtColumn()) |
52 | - ->setVisibility('protected'); |
|
52 | + ->setVisibility('protected'); |
|
53 | 53 | |
54 | 54 | if (! $class->hasMethod('init')) { |
55 | 55 | $class->addMethod('init')->setVisibility('public') |
56 | - ->setBody('parent::init();' . PHP_EOL); |
|
56 | + ->setBody('parent::init();' . PHP_EOL); |
|
57 | 57 | } |
58 | 58 | $class->getNamespace()->addUse(\Sirius\Orm\Behaviour\Timestamps::class); |
59 | 59 | $method = $class->getMethod('init'); |
@@ -66,35 +66,35 @@ discard block |
||
66 | 66 | public function observeBaseQueryClass(ClassType $class): ClassType |
67 | 67 | { |
68 | 68 | $class->addProperty('createdAtColumn', $this->behaviour->getCreatedAtColumn()) |
69 | - ->setVisibility('protected'); |
|
69 | + ->setVisibility('protected'); |
|
70 | 70 | $class->addProperty('updatedAtColumn', $this->behaviour->getUpdatedAtColumn()) |
71 | - ->setVisibility('protected'); |
|
71 | + ->setVisibility('protected'); |
|
72 | 72 | |
73 | 73 | // add methods |
74 | 74 | $class->addMethod('orderByFirstCreated') |
75 | - ->setVisibility('public') |
|
76 | - ->setBody(' |
|
75 | + ->setVisibility('public') |
|
76 | + ->setBody(' |
|
77 | 77 | $this->orderBy($this->createdAtColumn . \' ASC\'); |
78 | 78 | |
79 | 79 | return $this; |
80 | 80 | '); |
81 | 81 | $class->addMethod('orderByLastCreated') |
82 | - ->setVisibility('public') |
|
83 | - ->setBody(' |
|
82 | + ->setVisibility('public') |
|
83 | + ->setBody(' |
|
84 | 84 | $this->orderBy($this->createdAtColumn . \' DESC\'); |
85 | 85 | |
86 | 86 | return $this; |
87 | 87 | '); |
88 | 88 | $class->addMethod('orderByFirstUpdated') |
89 | - ->setVisibility('public') |
|
90 | - ->setBody(' |
|
89 | + ->setVisibility('public') |
|
90 | + ->setBody(' |
|
91 | 91 | $this->orderBy($this->updatedAtColumn . \' ASC\'); |
92 | 92 | |
93 | 93 | return $this; |
94 | 94 | '); |
95 | 95 | $class->addMethod('orderByLastCreated') |
96 | - ->setVisibility('public') |
|
97 | - ->setBody(' |
|
96 | + ->setVisibility('public') |
|
97 | + ->setBody(' |
|
98 | 98 | $this->orderBy($this->updatedAtColumn . \' DESC\'); |
99 | 99 | |
100 | 100 | return $this; |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $class->addProperty('updatedAtColumn', $this->behaviour->getUpdatedAtColumn()) |
52 | 52 | ->setVisibility('protected'); |
53 | 53 | |
54 | - if (! $class->hasMethod('init')) { |
|
54 | + if (!$class->hasMethod('init')) { |
|
55 | 55 | $class->addMethod('init')->setVisibility('public') |
56 | 56 | ->setBody('parent::init();' . PHP_EOL); |
57 | 57 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $class->getNamespace()->addUse(\Sirius\Orm\Action\Delete::class, 'DeleteAction'); |
54 | 54 | $class->getNamespace()->addUse(\Sirius\Orm\Action\Update::class, 'UpdateAction'); |
55 | 55 | $class->addProperty('deletedAtColumn', $this->behaviour->getDeletedAtColumn()) |
56 | - ->setVisibility('protected'); |
|
56 | + ->setVisibility('protected'); |
|
57 | 57 | |
58 | 58 | // |
59 | 59 | $method = $class->addMethod('newDeleteAction'); |
@@ -118,21 +118,21 @@ discard block |
||
118 | 118 | public function observeBaseQueryClass(ClassType $class): ClassType |
119 | 119 | { |
120 | 120 | $class->addProperty('deletedAtColumn', $this->behaviour->getDeletedAtColumn()) |
121 | - ->setVisibility('protected'); |
|
121 | + ->setVisibility('protected'); |
|
122 | 122 | |
123 | 123 | // add guard |
124 | 124 | if (! $class->hasMethod('init')) { |
125 | 125 | $class->addMethod('init') |
126 | - ->setVisibility(ClassType::VISIBILITY_PROTECTED) |
|
127 | - ->setBody('parent::init();' . PHP_EOL); |
|
126 | + ->setVisibility(ClassType::VISIBILITY_PROTECTED) |
|
127 | + ->setBody('parent::init();' . PHP_EOL); |
|
128 | 128 | } |
129 | 129 | $init = $class->getMethod('init'); |
130 | 130 | $init->addBody('$this->guards[] = $this->deletedAtColumn . \' IS NULL\';' . PHP_EOL); |
131 | 131 | |
132 | 132 | // add withTrashed() |
133 | 133 | $class->addMethod('withTrashed') |
134 | - ->setVisibility(ClassType::VISIBILITY_PUBLIC) |
|
135 | - ->setBody(' |
|
134 | + ->setVisibility(ClassType::VISIBILITY_PUBLIC) |
|
135 | + ->setBody(' |
|
136 | 136 | $guards = []; |
137 | 137 | foreach ($this->guards as $k => $v) { |
138 | 138 | if ($v != $this->deletedAtColumn . \' IS NULL\') { |
@@ -121,7 +121,7 @@ |
||
121 | 121 | ->setVisibility('protected'); |
122 | 122 | |
123 | 123 | // add guard |
124 | - if (! $class->hasMethod('init')) { |
|
124 | + if (!$class->hasMethod('init')) { |
|
125 | 125 | $class->addMethod('init') |
126 | 126 | ->setVisibility(ClassType::VISIBILITY_PROTECTED) |
127 | 127 | ->setBody('parent::init();' . PHP_EOL); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - return ! ! $value; |
|
73 | + return !!$value; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // phpcs:ignore |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | return $value; |
104 | 104 | } |
105 | 105 | |
106 | - return json_decode((string) $value, true); |
|
106 | + return json_decode((string)$value, true); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | public function json($value) |
110 | 110 | { |
111 | - if (! $value) { |
|
111 | + if (!$value) { |
|
112 | 112 | return new \ArrayObject(); |
113 | 113 | } |
114 | 114 | if (is_array($value)) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | // phpcs:ignore |
127 | 127 | public function json_for_db($value) |
128 | 128 | { |
129 | - if (! $value) { |
|
129 | + if (!$value) { |
|
130 | 130 | return null; |
131 | 131 | } |
132 | 132 | if (is_array($value)) { |