Skip to content

Commit af4c38f

Browse files
committed
Fix CS errors.
1 parent 7421d8a commit af4c38f

6 files changed

Lines changed: 39 additions & 34 deletions

File tree

src/Model/Behavior/TagBehavior.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use ArrayObject;
55
use Cake\Event\Event;
66
use Cake\ORM\Behavior;
7-
use Cake\Utility\Inflector;
87
use Cake\Utility\Text;
98
use RuntimeException;
109

@@ -33,15 +32,15 @@ class TagBehavior extends Behavior
3332
'className' => 'Muffin/Tags.Tagged',
3433
],
3534
'taggedCounter' => ['tag_count' => [
36-
'conditions' => []
35+
'conditions' => [],
3736
]],
3837
'implementedEvents' => [
3938
'Model.beforeMarshal' => 'beforeMarshal',
4039
],
4140
'implementedMethods' => [
4241
'normalizeTags' => 'normalizeTags',
4342
],
44-
'fkTableField' => 'fk_table'
43+
'fkTableField' => 'fk_table',
4544
];
4645

4746
/**
@@ -114,10 +113,10 @@ public function bindAssociations()
114113
if (!$table->hasAssociation($tagsAlias)) {
115114
$table->belongsToMany($tagsAlias, $tagsAssoc + [
116115
'through' => $table->{$taggedAlias}->getTarget(),
117-
'conditions' => $assocConditions
116+
'conditions' => $assocConditions,
118117
]);
119118
}
120-
119+
121120
if (!$table->{$tagsAlias}->hasAssociation($tableAlias)) {
122121
$table->{$tagsAlias}
123122
->belongsToMany($tableAlias, [
@@ -188,7 +187,7 @@ public function attachCounters()
188187
if (!$counterCache->getConfig($taggedAlias)) {
189188
$field = key($config['taggedCounter']);
190189
$config['taggedCounter']['tag_count']['conditions'] = [
191-
$taggedTable->aliasField($this->getConfig('fkTableField')) => $this->_table->getTable()
190+
$taggedTable->aliasField($this->getConfig('fkTableField')) => $this->_table->getTable(),
192191
];
193192
$counterCache->setConfig($this->_table->getAlias(), $config['taggedCounter']);
194193
}
@@ -209,7 +208,8 @@ public function normalizeTags($tags)
209208
$result = [];
210209

211210
$common = ['_joinData' => [$this->getConfig('fkTableField') => $this->_table->getTable()]];
212-
if ($namespace = $this->getConfig('namespace')) {
211+
$namespace = $this->getConfig('namespace');
212+
if ($namespace) {
213213
$common += compact('namespace');
214214
}
215215

@@ -230,7 +230,7 @@ public function normalizeTags($tags)
230230
}
231231
list($id, $label) = $this->_normalizeTag($tag);
232232
$result[] = $common + compact(empty($id) ? $df : $pk) + [
233-
'tag_key' => $tagKey
233+
'tag_key' => $tagKey,
234234
];
235235
}
236236

@@ -245,7 +245,7 @@ public function normalizeTags($tags)
245245
*/
246246
protected function _getTagKey($tag)
247247
{
248-
return strtolower(Text::slug($tag));
248+
return strtolower(Text::slug($tag));
249249
}
250250

251251
/**
@@ -262,12 +262,13 @@ protected function _tagExists($tag)
262262
$tagsTable->aliasField('tag_key') => $tag,
263263
])
264264
->select([
265-
$tagsTable->aliasField($tagsTable->getPrimaryKey())
265+
$tagsTable->aliasField($tagsTable->getPrimaryKey()),
266266
])
267267
->first();
268268
if (!empty($result)) {
269269
return $result->id;
270270
}
271+
271272
return null;
272273
}
273274

@@ -289,7 +290,7 @@ protected function _normalizeTag($tag)
289290

290291
return [
291292
trim($namespace),
292-
trim($label)
293+
trim($label),
293294
];
294295
}
295296
}

src/Model/Entity/TagAwareTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ public function untag($tags = null)
3838
$id = $this->get($table->getPrimaryKey());
3939
$untags = $behavior->normalizeTags($tags);
4040

41-
if (!$tags = $this->get($property)) {
41+
$tags = $this->get($property);
42+
if (!$tags) {
4243
$contain = [$behavior->getConfig('tagsAlias')];
4344
$tags = $table->get($id, compact('contain'))->get($property);
4445
}
4546

4647
$tagsTable = $table->{$behavior->getConfig('tagsAlias')};
4748
$pk = $tagsTable->getPrimaryKey();
4849
$df = $tagsTable->getDisplayField();
49-
50+
5051
foreach ($tags as $k => $tag) {
5152
$tags[$k] = [
5253
$pk => $tag->{$pk},
@@ -93,6 +94,7 @@ protected function _updateTags($tags, $saveStrategy)
9394
$table->patchEntity($this, [$assoc->getProperty() => $tags]);
9495
$result = $table->save($this);
9596
$assoc->setSaveStrategy($resetStrategy);
97+
9698
return $result;
9799
}
98100
}

src/Model/Entity/Tagged.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class Tagged extends Entity
1616
public $accessible = [
1717
'*' => false,
1818
];
19-
}
19+
}

src/Model/Table/TaggedTable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Muffin\Tags\Model\Table;
3+
34
use Cake\ORM\Table;
5+
46
/**
57
* TaggedTable
68
*/
@@ -17,4 +19,4 @@ public function initialize(array $config)
1719
$this->setTable('tags_tagged');
1820
$this->addBehavior('Timestamp');
1921
}
20-
}
22+
}

tests/TestCase/Model/Behavior/TagBehaviorTest.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use Cake\ORM\TableRegistry;
55
use Cake\TestSuite\TestCase;
6-
use Muffin\Tags\Model\Behavior\TagBehavior;
76

87
class TagBehaviorTest extends TestCase
98
{
@@ -36,7 +35,7 @@ public function testSavingDuplicates()
3635
{
3736
$entity = $this->Table->newEntity([
3837
'name' => 'Duplicate Tags?',
39-
'tags' => 'Color, Dark Color'
38+
'tags' => 'Color, Dark Color',
4039
]);
4140
$this->Table->save($entity);
4241
$Tags = $this->Table->Tagged->Tags;
@@ -76,44 +75,44 @@ public function testNormalizeTags()
7675
$expected = [
7776
0 => [
7877
'_joinData' => [
79-
'fk_table' => 'tags_muffins'
78+
'fk_table' => 'tags_muffins',
8079
],
8180
'label' => 'foo',
82-
'tag_key' => 'foo'
81+
'tag_key' => 'foo',
8382
],
8483
1 => [
8584
'_joinData' => [
86-
'fk_table' => 'tags_muffins'
85+
'fk_table' => 'tags_muffins',
8786
],
8887
'id' => '3',
89-
'tag_key' => '3-foobar'
88+
'tag_key' => '3-foobar',
9089
],
9190
2 => [
9291
'_joinData' => [
93-
'fk_table' => 'tags_muffins'
92+
'fk_table' => 'tags_muffins',
9493
],
9594
'label' => 'bar',
96-
'tag_key' => 'bar'
97-
]
95+
'tag_key' => 'bar',
96+
],
9897
];
9998
$this->assertEquals($expected, $result);
10099

101100
$result = $this->Behavior->normalizeTags(['foo', 'bar']);
102101
$expected = [
103102
0 => [
104103
'_joinData' => [
105-
'fk_table' => 'tags_muffins'
104+
'fk_table' => 'tags_muffins',
106105
],
107106
'label' => 'foo',
108-
'tag_key' => 'foo'
107+
'tag_key' => 'foo',
109108
],
110109
1 => [
111110
'_joinData' => [
112-
'fk_table' => 'tags_muffins'
111+
'fk_table' => 'tags_muffins',
113112
],
114113
'label' => 'bar',
115-
'tag_key' => 'bar'
116-
]
114+
'tag_key' => 'bar',
115+
],
117116
];
118117

119118
$this->assertEquals($expected, $result);
@@ -234,7 +233,7 @@ public function testCounterCacheDisabled()
234233
$this->Table->Tagged->removeBehavior('CounterCache');
235234

236235
$this->Table->addBehavior('Muffin/Tags.Tag', [
237-
'taggedCounter' => false
236+
'taggedCounter' => false,
238237
]);
239238

240239
$count = $this->Table->get(1)->tag_count;
@@ -260,8 +259,8 @@ public function testCounterCacheFieldException()
260259
$table = TableRegistry::getTableLocator()->get('Muffin/Tags.Buns', ['table' => 'tags_buns']);
261260
$table->addBehavior('Muffin/Tags.Tag', [
262261
'taggedCounter' => [
263-
'non_existent' => []
264-
]
262+
'non_existent' => [],
263+
],
265264
]);
266265
}
267266

tests/bootstrap.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return $root;
1616
}
1717
} while ($root !== $lastRoot);
18-
18+
1919
throw new Exception("Cannot find the root of the application, unable to run tests");
2020
};
2121

@@ -25,9 +25,10 @@
2525
chdir($root);
2626
if (file_exists($root . '/config/bootstrap.php')) {
2727
require $root . '/config/bootstrap.php';
28+
2829
return;
2930
}
3031

3132
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
3233

33-
\Cake\Core\Plugin::load('Muffin/Tags', ['path' => dirname(dirname(__FILE__)) . DS]);
34+
\Cake\Core\Plugin::load('Muffin/Tags', ['path' => dirname(dirname(__FILE__)) . DS]);

0 commit comments

Comments
 (0)