Skip to content

Commit 6fdb18e

Browse files
committed
class cleaning (quotes)
1 parent c8d329f commit 6fdb18e

File tree

4 files changed

+66
-63
lines changed

4 files changed

+66
-63
lines changed

src/Ubiquity/orm/creator/Member.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function __construct($name, $access = 'private') {
4242
}
4343

4444
public function __toString() {
45-
$annotationsStr = "";
45+
$annotationsStr = '';
4646
if (sizeof($this->annotations) > 0) {
4747
$annotationsStr = "\n\t/**";
4848
$annotations = $this->annotations;
4949
\array_walk($annotations, function ($item) {
50-
return $item . "";
50+
return $item . '';
5151
});
5252
if (\sizeof($annotations) > 1) {
5353
$annotationsStr .= "\n\t * " . implode("\n\t * ", $annotations);
@@ -69,8 +69,8 @@ public function setPrimary() {
6969
public function setDbType($infos) {
7070
$annot = new ColumnAnnotation();
7171
$annot->name = $this->name;
72-
$annot->dbType = $infos["Type"];
73-
$annot->nullable = (\strtolower($infos["Nullable"]) === "yes");
72+
$annot->dbType = $infos['Type'];
73+
$annot->nullable = (\strtolower($infos['Nullable']) === 'yes');
7474
$this->annotations["column"] = $annot;
7575
}
7676

@@ -147,10 +147,10 @@ public function addManyToMany($targetEntity, $inversedBy, $joinTable, $joinColum
147147
$manyToMany->inversedBy = $inversedBy;
148148
$jt = new JoinTableAnnotation();
149149
$jt->name = $joinTable;
150-
if (\sizeof($joinColumns) == 2) {
150+
if (\count($joinColumns) == 2) {
151151
$jt->joinColumns = $joinColumns;
152152
}
153-
if (\sizeof($inverseJoinColumns) == 2) {
153+
if (\count($inverseJoinColumns) == 2) {
154154
$jt->inverseJoinColumns = $inverseJoinColumns;
155155
}
156156
$this->annotations[] = $manyToMany;
@@ -197,22 +197,22 @@ public function hasAnnotations() {
197197
}
198198

199199
public function isNullable() {
200-
if (isset($this->annotations["column"]))
201-
return $this->annotations["column"]->nullable;
200+
if (isset($this->annotations['column']))
201+
return $this->annotations['column']->nullable;
202202
return false;
203203
}
204204

205205
public function getDbType() {
206-
if (isset($this->annotations["column"]))
207-
return $this->annotations["column"]->dbType;
208-
return "mixed";
206+
if (isset($this->annotations['column']))
207+
return $this->annotations['column']->dbType;
208+
return 'mixed';
209209
}
210210

211211
public function addValidators() {
212212
$parser = new ValidationModelGenerator($this->getDbType(), $this->name, ! $this->isNullable(), $this->primary);
213213
$validators = $parser->parse();
214-
if (sizeof($validators)) {
215-
$this->annotations = array_merge($this->annotations, $validators);
214+
if ($validators && \count($validators)) {
215+
$this->annotations = \array_merge($this->annotations, $validators);
216216
}
217217
}
218218

src/Ubiquity/orm/creator/Model.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private function checkForUniqName(&$member) {
4444
}
4545
}
4646

47-
public function __construct($name, $namespace = "models", $memberAccess = 'private') {
47+
public function __construct($name, $namespace = 'models', $memberAccess = 'private') {
4848
$this->table = $name;
4949
$this->name = \ucfirst($name);
5050
$this->members = array();
@@ -108,21 +108,21 @@ public function addManyToMany($member, $targetEntity, $inversedBy, $joinTable, $
108108

109109
public function __toString() {
110110
$result = "<?php\n";
111-
if ($this->namespace !== "" && $this->namespace !== null) {
112-
$result .= "namespace " . $this->namespace . ";\n";
111+
if ($this->namespace !== '' && $this->namespace !== null) {
112+
$result .= 'namespace ' . $this->namespace . ";\n";
113113
}
114114
if ($this->database != null && $this->database !== 'default') {
115115
$result .= $this->getAnnotation("database('{$this->database}')");
116116
}
117117
if ($this->table !== $this->name) {
118118
$result .= $this->getAnnotation("table('{$this->table}')");
119119
}
120-
$result .= "class " . ucfirst($this->name) . "{";
120+
$result .= 'class ' . \ucfirst($this->name) . '{';
121121
$members = $this->members;
122122
\array_walk($members, function ($item) {
123-
return $item . "";
123+
return $item . '';
124124
});
125-
$result .= \implode("", $members);
125+
$result .= \implode('', $members);
126126
foreach ($members as $member) {
127127
$result .= $member->getGetter();
128128
$result .= $member->getSetter();
@@ -133,8 +133,8 @@ public function __toString() {
133133
}
134134

135135
public function getName() {
136-
$namespace = "";
137-
if ($this->namespace !== "" && $this->namespace !== null)
136+
$namespace = '';
137+
if ($this->namespace !== '' && $this->namespace !== null)
138138
$namespace = $this->namespace . '\\';
139139
return $namespace . $this->name;
140140
}
@@ -168,17 +168,18 @@ public function getPrimaryKey() {
168168

169169
public function getPkName() {
170170
$pk = $this->getPrimaryKey();
171-
if (isset($pk))
171+
if (isset($pk)) {
172172
return $pk->getName();
173+
}
173174
return null;
174175
}
175176

176177
public function getDefaultFk() {
177-
return "id" . $this->name;
178+
return 'id' . $this->name;
178179
}
179180

180181
public function getManyToOneMembers() {
181-
$result = array();
182+
$result = [];
182183
foreach ($this->members as $member) {
183184
if ($member->isManyToOne() === true) {
184185
$result[] = $member;

src/Ubiquity/orm/creator/ModelsCreator.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ protected function init($config, $offset = 'default') {
4242
public function create($config, $initCache = true, $singleTable = null, $offset = 'default', $memberAccess = 'private') {
4343
$this->init($config, $offset);
4444
$this->memberAccess = $memberAccess;
45-
$dirPostfix = "";
46-
$nsPostfix = "";
45+
$dirPostfix = '';
46+
$nsPostfix = '';
4747
if ($offset !== 'default') {
4848
$dirPostfix = \DS . $offset;
49-
$nsPostfix = "\\" . $offset;
49+
$nsPostfix = '\\' . $offset;
5050
}
5151
$modelsDir = Startup::getModelsCompletePath() . $dirPostfix;
5252
if (UFileSystem::safeMkdir($modelsDir)) {
5353
$this->tables = $this->getTablesName();
5454
CacheManager::checkCache($config);
5555

5656
foreach ($this->tables as $table) {
57-
$class = new Model($table, $config["mvcNS"]["models"] . $nsPostfix, $memberAccess);
57+
$class = new Model($table, $config['mvcNS']['models'] . $nsPostfix, $memberAccess);
5858
$class->setDatabase($offset);
5959

6060
$fieldsInfos = $this->getFieldsInfos($table);
@@ -79,11 +79,11 @@ public function create($config, $initCache = true, $singleTable = null, $offset
7979
foreach ($this->classes as $table => $class) {
8080
$name = $class->getSimpleName();
8181
echo "Creating the {$name} class\n";
82-
$this->writeFile($modelsDir . \DS . $name . ".php", $class);
82+
$this->writeFile($modelsDir . \DS . $name . '.php', $class);
8383
}
8484
}
8585
if ($initCache === true) {
86-
CacheManager::initCache($config, "models");
86+
CacheManager::initCache($config, 'models');
8787
}
8888
}
8989
}
@@ -92,7 +92,7 @@ protected function createOneClass($singleTable, $modelsDir) {
9292
if (isset($this->classes[$singleTable])) {
9393
$class = $this->classes[$singleTable];
9494
echo "Creating the {$class->getName()} class\n";
95-
$this->writeFile($modelsDir . \DS . $class->getSimpleName() . ".php", $class);
95+
$this->writeFile($modelsDir . \DS . $class->getSimpleName() . '.php', $class);
9696
} else {
9797
echo "The {$singleTable} table does not exist in the database\n";
9898
}
@@ -105,9 +105,9 @@ protected function createRelations() {
105105
$fks = $this->getForeignKeys($table, $key, $this->config['dbName'] ?? '');
106106
foreach ($fks as $fk) {
107107
$field = \lcfirst($table);
108-
$fkTable = $fk["TABLE_NAME"];
109-
$this->classes[$table]->addOneToMany(\lcfirst($fkTable) . "s", \lcfirst($table), $this->classes[$fkTable]->getName());
110-
$this->classes[$fkTable]->addManyToOne($field, \lcfirst($fk["COLUMN_NAME"]), $class->getName());
108+
$fkTable = $fk['TABLE_NAME'];
109+
$this->classes[$table]->addOneToMany(\lcfirst($fkTable) . 's', \lcfirst($table), $this->classes[$fkTable]->getName());
110+
$this->classes[$fkTable]->addManyToOne($field, \lcfirst($fk['COLUMN_NAME']), $class->getName());
111111
}
112112
}
113113
}
@@ -116,8 +116,9 @@ protected function createRelations() {
116116

117117
protected function getTableName($classname) {
118118
foreach ($this->classes as $table => $class) {
119-
if ($class->getName() === $classname)
119+
if ($class->getName() === $classname) {
120120
return $table;
121+
}
121122
}
122123
$posSlash = strrpos($classname, '\\');
123124
$tablename = substr($classname, $posSlash + 1);
@@ -135,8 +136,8 @@ protected function createManyToMany() {
135136
$table2 = $this->getTableName($manyToOne2->className);
136137
$class1 = $this->classes[$table1];
137138
$class2 = $this->classes[$table2];
138-
$table1Member = \lcfirst($table1) . "s";
139-
$table2Member = \lcfirst($table2) . "s";
139+
$table1Member = \lcfirst($table1) . 's';
140+
$table2Member = \lcfirst($table2) . 's';
140141
$joinTable1 = $this->getJoinTableArray($class1, $manyToOne1);
141142
$joinTable2 = $this->getJoinTableArray($class2, $manyToOne2);
142143
$class1->addManyToMany($table2Member, $manyToOne2->className, $table1Member, $table, $joinTable1, $joinTable2);
@@ -159,14 +160,14 @@ protected function getJoinTableArray(Model $class, JoinColumnAnnotation $joinCol
159160
if ($fk !== $dFk) {
160161
if ($pk !== null && $fk !== null)
161162
return [
162-
"name" => $fk,
163-
"referencedColumnName" => $pk->getName()
163+
'name' => $fk,
164+
'referencedColumnName' => $pk->getName()
164165
];
165166
}
166167
return [];
167168
}
168169

169170
protected function writeFile($filename, $data) {
170-
return file_put_contents($filename, $data);
171+
return \file_put_contents($filename, $data);
171172
}
172173
}

src/Ubiquity/orm/reverse/TableReversor.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ public function init($metas) {
3737
}
3838

3939
public function generateSQL(DbGenerator $generator) {
40-
$table = $this->metas["#tableName"];
41-
$primaryKeys = $this->metas["#primaryKeys"];
40+
$table = $this->metas['#tableName'];
41+
$primaryKeys = $this->metas['#primaryKeys'];
4242
$serializables = $this->getSerializableFields();
43-
$nullables = $this->metas["#nullable"];
44-
$fieldTypes = $this->metas["#fieldTypes"];
45-
$manyToOnes = $this->metas["#manyToOne"];
43+
$nullables = $this->metas['#nullable'];
44+
$fieldTypes = $this->metas['#fieldTypes'];
45+
$manyToOnes = $this->metas['#manyToOne'];
4646
$manyToManys = [];
47-
if (isset($this->metas["#manyToMany"]))
48-
$manyToManys = $this->metas["#manyToMany"];
47+
if (isset($this->metas['#manyToMany'])) {
48+
$manyToManys = $this->metas['#manyToMany'];
49+
}
4950
$this->scanManyToManys($generator, $manyToManys);
5051
$this->generatePks($generator, $primaryKeys, $table, $fieldTypes, $nullables);
5152
$this->generateForeignKeys($generator, $manyToOnes, $table);
@@ -56,28 +57,28 @@ public function generateSQL(DbGenerator $generator) {
5657
foreach ($this->fkFieldsToAdd as $fkField) {
5758
$generator->addKey($table, [
5859
$fkField
59-
], "");
60+
], '');
6061
}
6162
}
6263

6364
protected function getSerializableFields() {
64-
$notSerializable = $this->metas["#notSerializable"];
65-
$fieldNames = $this->metas["#fieldNames"];
65+
$notSerializable = $this->metas['#notSerializable'];
66+
$fieldNames = $this->metas['#fieldNames'];
6667
return \array_diff($fieldNames, $notSerializable);
6768
}
6869

6970
protected function scanManyToManys(DbGenerator $generator, $manyToManys) {
7071
foreach ($manyToManys as $member => $manyToMany) {
71-
if (isset($this->metas["#joinTable"][$member])) {
72-
$annotJoinTable = $this->metas["#joinTable"][$member];
73-
$generator->addManyToMany($annotJoinTable["name"], $manyToMany["targetEntity"]);
72+
if (isset($this->metas['#joinTable'][$member])) {
73+
$annotJoinTable = $this->metas['#joinTable'][$member];
74+
$generator->addManyToMany($annotJoinTable['name'], $manyToMany['targetEntity']);
7475
}
7576
}
7677
}
7778

7879
protected function generatePks(DbGenerator $generator, $primaryKeys, $table, $fieldTypes, $nullables) {
7980
$generator->addKey($table, $primaryKeys);
80-
if (\sizeof($primaryKeys) === 1 && $generator->isInt($fieldTypes[\current($primaryKeys)])) {
81+
if (\count($primaryKeys) === 1 && $generator->isInt($fieldTypes[\current($primaryKeys)])) {
8182
$generator->addAutoInc($table, $this->getFieldAttributes($generator, \current($primaryKeys), $nullables, $fieldTypes));
8283
}
8384
}
@@ -95,26 +96,26 @@ public function getFieldAttributes(DbGenerator $generator, $field, $nullables, $
9596
}
9697

9798
protected function _generateFieldAttributes($field, $nullables, $fieldTypes) {
98-
$nullable = "NOT NULL";
99+
$nullable = 'NOT NULL';
99100
if (\array_search($field, $nullables) !== false) {
100-
$nullable = "";
101+
$nullable = '';
101102
}
102103
return [
103-
"name" => $field,
104-
"type" => $fieldTypes[$field],
105-
"extra" => $nullable
104+
'name' => $field,
105+
'type' => $fieldTypes[$field],
106+
'extra' => $nullable
106107
];
107108
}
108109

109110
protected function generateForeignKey(DbGenerator $generator, $tableName, $member) {
110-
$fieldAnnot = OrmUtils::getMemberJoinColumns("", $member, $this->metas);
111+
$fieldAnnot = OrmUtils::getMemberJoinColumns('', $member, $this->metas);
111112
if ($fieldAnnot !== null) {
112113
$annotationArray = $fieldAnnot[1];
113-
$referencesTableName = OrmUtils::getTableName($annotationArray["className"]);
114-
$referencesFieldName = OrmUtils::getFirstKey($annotationArray["className"]);
114+
$referencesTableName = OrmUtils::getTableName($annotationArray['className']);
115+
$referencesFieldName = OrmUtils::getFirstKey($annotationArray['className']);
115116
$fkFieldName = $fieldAnnot[0];
116117
$this->fkFieldsToAdd[] = $fkFieldName;
117-
$this->fkFieldTypesToAdd[$fkFieldName] = OrmUtils::getFieldType($annotationArray["className"], $referencesFieldName);
118+
$this->fkFieldTypesToAdd[$fkFieldName] = OrmUtils::getFieldType($annotationArray['className'], $referencesFieldName);
118119
$generator->addForeignKey($tableName, $fkFieldName, $referencesTableName, $referencesFieldName);
119120
}
120121
}

0 commit comments

Comments
 (0)