Completed
Pull Request — master (#8)
by
unknown
03:08
created
components/terms/BaseTerm.php 2 patches
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -74,8 +74,9 @@  discard block
 block discarded – undo
74 74
     }
75 75
 
76 76
     public function canInstall() {
77
-        if(!$this->getTable())
78
-            return 'Missing "table" property';
77
+        if(!$this->getTable()) {
78
+                    return 'Missing "table" property';
79
+        }
79 80
         return true;
80 81
     }
81 82
 
@@ -95,10 +96,12 @@  discard block
 block discarded – undo
95 96
 
96 97
     public function getRefTableName()
97 98
     {
98
-        if(strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name
99
+        if(strpos($this->refTable, '\\') === FALSE) {
100
+            //not an AR class but a table name
99 101
             return $this->refTable;
100
-        else
101
-            return call_user_func([$this->refTable, 'tableName']);
102
+        } else {
103
+                    return call_user_func([$this->refTable, 'tableName']);
104
+        }
102 105
     }
103 106
 
104 107
     public function getTable()
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 
36 36
     public function removeTerm($object_id, $params = [])
37 37
     {
38
-        if(empty($params)) {
38
+        if (empty($params)) {
39 39
             $params = $this->getTerms($object_id);
40 40
         }
41 41
 
42
-        foreach($params as $item) {
42
+        foreach ($params as $item) {
43 43
             $term = $this->getTaxonomyTerm($item);
44 44
             $data['term_id'] = $term->id;
45 45
             $data['object_id'] = $object_id;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                 $this->getDb()->createCommand()->delete($this->table, $data)->execute();
50 50
 
51 51
                 $term->updateCounters(['total_count' => -1]);
52
-                Taxonomydef::updateAllCounters(['total_count' => -1], [ 'id' => $this->id ]);
52
+                Taxonomydef::updateAllCounters(['total_count' => -1], ['id' => $this->id]);
53 53
             }
54 54
         }
55 55
     }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
             ->andFilterWhere(['taxonomy_terms.term' => $name]);
63 63
 
64 64
         if ($object_id) {
65
-            $query->innerJoin($this->table, $this->table . '.term_id = taxonomy_terms.id')
65
+            $query->innerJoin($this->table, $this->table.'.term_id = taxonomy_terms.id')
66 66
                   ->onCondition("$this->table.object_id = $object_id");
67 67
         }
68 68
         
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     }
108 108
 
109 109
     public function canInstall() {
110
-        if(!$this->getTable())
110
+        if (!$this->getTable())
111 111
             return 'Missing "table" property';
112 112
         return true;
113 113
     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     public function getTaxonomyTerm($name, $create = true)
116 116
     {
117 117
         $term = TaxonomyTerms::findOne(['term'=>$name, 'taxonomy_id' => $this->id]);
118
-        if($create and !isset($term))
118
+        if ($create and !isset($term))
119 119
         {
120 120
             $term = new TaxonomyTerms();
121 121
             $term->taxonomy_id = $this->id;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 
129 129
     public function getRefTableName()
130 130
     {
131
-        if(strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name
131
+        if (strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name
132 132
             return $this->refTable;
133 133
         else
134 134
             return call_user_func([$this->refTable, 'tableName']);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         if (!preg_match('/^\w+$/', $this->name)) {
150 150
             throw new Exception('The migration name should contain letters, digits and/or underscore characters only.');
151 151
         }
152
-        $name = 'm' . gmdate('ymd_His') . '_' . $this->name;
152
+        $name = 'm'.gmdate('ymd_His').'_'.$this->name;
153 153
         return $name;
154 154
     }
155 155
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     {
158 158
 
159 159
         $name = $this->getMigrationFile();
160
-        $file = Yii::getAlias($this->migrationPath . DIRECTORY_SEPARATOR . $name . '.php');
160
+        $file = Yii::getAlias($this->migrationPath.DIRECTORY_SEPARATOR.$name.'.php');
161 161
 
162 162
         //$data = get_object_vars($this);
163 163
         $data = [];
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         $data['migration'] = $name;
169 169
 
170 170
         $this->migration = $name;
171
-        $content = Yii::$app->getView()->renderFile(Yii::getAlias($this->templateFile), [ 'data' => $data ]);
171
+        $content = Yii::$app->getView()->renderFile(Yii::getAlias($this->templateFile), ['data' => $data]);
172 172
         file_put_contents($file, $content);
173 173
         return $name;
174 174
     }
Please login to merge, or discard this patch.
behaviors/PropertySupportBehavior.php 1 patch
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -4,9 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use Yii;
6 6
 use yii\base\Behavior;
7
-use yii\base\Event;
8
-use yii\db\ActiveRecord;
9
-use yii\db\AfterSaveEvent;
10 7
 
11 8
 /**
12 9
  * @author Nikolay Traykov
Please login to merge, or discard this patch.
behaviors/TagSupportBehavior.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use Yii;
6 6
 use yii\base\Behavior;
7
-use yii\base\Event;
8 7
 use yii\db\ActiveRecord;
9 8
 use yii\db\AfterSaveEvent;
10 9
 
Please login to merge, or discard this patch.
components/terms/PropertyTerm.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
 class PropertyTerm extends BaseTerm
19 19
 {
20
-    public $templateFile = '@nkostadinov/taxonomy/migrations/template/properties.php' ;
20
+    public $templateFile = '@nkostadinov/taxonomy/migrations/template/properties.php';
21 21
 
22 22
     public $updateOnExist = true;
23 23
 
@@ -33,14 +33,14 @@  discard block
 block discarded – undo
33 33
             'value' => Schema::TYPE_STRING,
34 34
         ]);
35 35
         if ($migration->db->driverName === 'mysql') {
36
-            $migration->addForeignKey('fk_' . $this->getTable() . '_' . $this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE');
37
-            $migration->addForeignKey('fk_' . $this->getTable() . '_' . TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE');
36
+            $migration->addForeignKey('fk_'.$this->getTable().'_'.$this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE');
37
+            $migration->addForeignKey('fk_'.$this->getTable().'_'.TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE');
38 38
         }
39 39
     }
40 40
 
41 41
     public function addTerm($object_id, $params)
42 42
     {
43
-        foreach($params as $item => $value) {
43
+        foreach ($params as $item => $value) {
44 44
             $term = TaxonomyTerms::findOne(['term' => $item, 'taxonomy_id' => $this->id]);
45 45
             if (!isset($term)) {
46 46
                 $term = new TaxonomyTerms();
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 } catch (Exception $e) {
67 67
                     $transaction->rollBack();
68 68
                 }
69
-            } elseif($this->updateOnExist) {
69
+            } elseif ($this->updateOnExist) {
70 70
                 $this->getDb()->createCommand()->update($this->getTable(), ['value' => $value], $data)->execute();
71 71
             }
72 72
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     public function removeTerm($object_id, $params = [])
76 76
     {
77 77
         $terms = $this->getTerms($object_id, $params);
78
-        foreach($terms as $term => $value) {
78
+        foreach ($terms as $term => $value) {
79 79
             $term = $this->getTaxonomyTerm($term);
80 80
             $data['term_id'] = $term->id;
81 81
             $data['object_id'] = $object_id;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
                 $this->getDb()->createCommand()->delete($this->getTable(), $data)->execute();
86 86
 
87 87
                 $term->updateCounters(['total_count' => -1]);
88
-                TaxonomyDef::updateAllCounters(['total_count' => -1], [ 'id' => $this->id ]);
88
+                TaxonomyDef::updateAllCounters(['total_count' => -1], ['id' => $this->id]);
89 89
             }
90 90
         }
91 91
     }
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
     public function getTerms($object_id, $name = [])
94 94
     {
95 95
         $query = (new Query())
96
-            ->select(TaxonomyTerms::tableName() . '.term, ' . $this->getTable() . '.value')
96
+            ->select(TaxonomyTerms::tableName().'.term, '.$this->getTable().'.value')
97 97
             ->from(TaxonomyTerms::tableName())
98
-            ->innerJoin($this->getTable(), $this->getTable() . '.term_id = taxonomy_terms.id and ' . $this->getTable() . '.object_id=:object_id',
98
+            ->innerJoin($this->getTable(), $this->getTable().'.term_id = taxonomy_terms.id and '.$this->getTable().'.object_id=:object_id',
99 99
                 [':object_id' => $object_id])
100
-            ->andFilterWhere([TaxonomyTerms::tableName() . '.term' => $name]);
100
+            ->andFilterWhere([TaxonomyTerms::tableName().'.term' => $name]);
101 101
 
102 102
         return ArrayHelper::map($query->all(), 'term', 'value');
103 103
     }
Please login to merge, or discard this patch.
components/terms/CategoryTerm.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
     {
31 31
         $cachedParents = [];
32 32
 
33
-        $addTerm = function ($parent, $item) use ($object_id, &$cachedParents, &$addTerm) {
33
+        $addTerm = function($parent, $item) use ($object_id, &$cachedParents, &$addTerm) {
34 34
             if ($this->detectLoop($parent, $item)) {
35 35
                 throw new InvalidCallException('Loop detected! Cannot add parent as a child!');
36 36
             }
Please login to merge, or discard this patch.