Conditions | 5 |
Paths | 192 |
Total Lines | 74 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
12 | public function testConfiguration() |
||
13 | { |
||
14 | $post = new Post(); |
||
15 | $post->detachBehavior('ml'); |
||
16 | |||
17 | try { |
||
18 | $post->attachBehavior('ml', [ |
||
19 | 'class' => MultilingualBehavior::className(), |
||
20 | 'languages' => [], |
||
21 | ]); |
||
22 | $this->fail("Expected exception not thrown"); |
||
23 | } catch (InvalidConfigException $e) { |
||
24 | $this->assertEquals(101, $e->getCode()); |
||
25 | } |
||
26 | |||
27 | try { |
||
28 | $post->detachBehavior('ml'); |
||
29 | $post->attachBehavior('ml', [ |
||
30 | 'class' => MultilingualBehavior::className(), |
||
31 | 'languages' => 'Some value', |
||
32 | ]); |
||
33 | $this->fail("Expected exception not thrown"); |
||
34 | } catch (InvalidConfigException $e) { |
||
35 | $this->assertEquals(101, $e->getCode()); |
||
36 | } |
||
37 | |||
38 | try { |
||
39 | $post->detachBehavior('ml'); |
||
40 | $post->attachBehavior('ml', [ |
||
41 | 'class' => MultilingualBehavior::className(), |
||
42 | 'languages' => [ |
||
43 | 'ru' => 'Russian', |
||
44 | 'en-US' => 'English', |
||
45 | ], |
||
46 | 'langForeignKey' => 'post_id', |
||
47 | 'tableName' => "{{%postLang}}", |
||
48 | ]); |
||
49 | $this->fail("Expected exception not thrown"); |
||
50 | } catch (InvalidConfigException $e) { |
||
51 | $this->assertEquals(103, $e->getCode()); |
||
52 | } |
||
53 | |||
54 | try { |
||
55 | $post->detachBehavior('ml'); |
||
56 | $post->attachBehavior('ml', [ |
||
57 | 'class' => MultilingualBehavior::className(), |
||
58 | 'languages' => [ |
||
59 | 'ru' => 'Russian', |
||
60 | 'en-US' => 'English', |
||
61 | ], |
||
62 | 'attributes' => [ |
||
63 | 'title', 'body', |
||
64 | ] |
||
65 | ]); |
||
66 | $this->fail("Expected exception not thrown"); |
||
67 | } catch (InvalidConfigException $e) { |
||
68 | $this->assertEquals(105, $e->getCode()); |
||
69 | } |
||
70 | |||
71 | $post->detachBehavior('ml'); |
||
72 | $post->attachBehavior('ml', [ |
||
73 | 'class' => MultilingualBehavior::className(), |
||
74 | 'languages' => [ |
||
75 | 'ru' => 'Russian', |
||
76 | 'en-US' => 'English', |
||
77 | ], |
||
78 | 'langForeignKey' => 'post_id', |
||
79 | 'attributes' => [ |
||
80 | 'title', 'body', |
||
81 | ] |
||
82 | ]); |
||
83 | |||
84 | $this->assertNotNull($post->defaultLanguage); |
||
85 | } |
||
86 | |||
219 |