1 | <?php |
||
13 | class ModelService extends AbstractService { |
||
14 | |||
15 | /** @var ModelReader */ |
||
16 | private $reader = null; |
||
17 | |||
18 | public function read(Project $project = null) { |
||
28 | |||
29 | /** |
||
30 | * @return ModelReader |
||
31 | 12 | */ |
|
32 | 12 | private function getReader() { |
|
38 | 12 | ||
39 | /** |
||
40 | 12 | * Returns the propel schema. The three locations, where the schema is looked up in: |
|
41 | 12 | * |
|
42 | 12 | * @return string|null the path to the schema |
|
43 | 12 | */ |
|
44 | 12 | public function getSchema() { |
|
51 | |||
52 | public function isCoreSchema() { |
||
55 | 12 | ||
56 | public function hasSchema() { |
||
59 | 3 | ||
60 | /** |
||
61 | * Returns the propel database |
||
62 | * |
||
63 | * @return Database |
||
64 | */ |
||
65 | public function getDatabase() { |
||
68 | |||
69 | /** |
||
70 | * Returns the tableName for a given name |
||
71 | * |
||
72 | 12 | * @param String $name tableName or modelName |
|
73 | 12 | * @return String tableName |
|
74 | 12 | */ |
|
75 | 12 | public function getTableName($name) { |
|
78 | |||
79 | 12 | /** |
|
80 | * Returns all model names |
||
81 | * |
||
82 | * @return Set |
||
83 | */ |
||
84 | public function getModelNames() { |
||
87 | |||
88 | 11 | /** |
|
89 | 11 | * Returns the propel models from the database, where table namespace matches package namespace |
|
90 | 11 | * |
|
91 | 11 | * @return Map |
|
92 | 11 | */ |
|
93 | public function getModels() { |
||
96 | |||
97 | /** |
||
98 | * Returns the model for the given name |
||
99 | * |
||
100 | * @param String $name modelName or tableName |
||
101 | * @return Table |
||
102 | */ |
||
103 | public function getModel($name) { |
||
106 | |||
107 | // /** |
||
108 | // * Returns the model names for a given package |
||
109 | // * |
||
110 | // * @param PackageSchema $package a package to search models for, if omitted global package is used |
||
111 | // * @return array array with string of model names |
||
112 | // */ |
||
113 | // public function getPackageModelNames(PackageSchema $package = null) { |
||
114 | // if ($package === null) { |
||
115 | // $package = $this->packageService->getPackage(); |
||
116 | // } |
||
117 | 1 | ||
118 | 1 | // $models = []; |
|
|
|||
119 | 1 | // // if this is a core-module, find the related model |
|
120 | 1 | // if ($package->getVendor() == 'keeko' && $this->isCoreSchema()) { |
|
121 | // $model = $package->getName(); |
||
122 | 1 | // if ($this->hasModel($model)) { |
|
123 | // $models [] = $model; |
||
124 | 1 | // } |
|
125 | 1 | // } |
|
126 | 1 | ||
127 | 1 | // // anyway, generate all |
|
128 | 1 | // else { |
|
129 | 1 | // foreach ($this->getModels() as $model) { |
|
130 | // $models [] = $model->getOriginCommonName(); |
||
131 | 1 | // } |
|
132 | // } |
||
133 | |||
134 | // return $models; |
||
135 | // } |
||
136 | |||
137 | /** |
||
138 | * Checks whether the given model exists |
||
139 | * |
||
140 | 7 | * @param String $name tableName or modelName |
|
141 | 7 | * @return boolean |
|
142 | 7 | */ |
|
143 | public function hasModel($name) { |
||
146 | |||
147 | 7 | /** |
|
148 | * Parses the model name from a given action name |
||
149 | 7 | * |
|
150 | * @param ActionSchema $action |
||
151 | * @return String modelName |
||
152 | */ |
||
153 | public function getModelNameByAction(ActionSchema $action) { |
||
161 | |||
162 | /** |
||
163 | * Returns the full model object name, including namespace |
||
164 | * |
||
165 | * @param ActionSchema $action |
||
166 | * @return String fullModelObjectName |
||
167 | 1 | */ |
|
168 | 1 | public function getFullModelObjectName(ActionSchema $action) { |
|
176 | 1 | ||
177 | /** |
||
178 | 1 | * Returns wether the given action refers to a model. |
|
179 | 1 | * |
|
180 | * Examples: |
||
181 | 1 | * |
|
182 | * Action: user-create => model: user |
||
183 | * Action: recover-password => no model |
||
184 | * |
||
185 | * @param ActionSchema $action |
||
186 | * @return boolean |
||
187 | */ |
||
188 | public function isModelAction(ActionSchema $action) { |
||
192 | |||
193 | /** |
||
194 | * Returns all model relationships. |
||
195 | * |
||
196 | * @param Table $model |
||
197 | * @return Relationships |
||
198 | */ |
||
199 | public function getRelationships(Table $model) { |
||
202 | |||
203 | /** |
||
204 | * Returns a relationship for a given related type name on a given model |
||
205 | * |
||
206 | * @param Table $model |
||
207 | * @param string $relatedTypeName |
||
208 | * @return Relationship |
||
209 | */ |
||
210 | public function getRelationship(Table $model, $relatedTypeName) { |
||
214 | } |
||
215 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.