| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 18 | public static function init() |
||
| 19 | { |
||
| 20 | self::$users = [ |
||
| 21 | '1' => new User([ |
||
| 22 | 'id' => '1', |
||
| 23 | 'email' => '[email protected]', |
||
| 24 | 'firstName' => 'John', |
||
| 25 | 'lastName' => 'Doe' |
||
| 26 | ]), |
||
| 27 | '2' => new User([ |
||
| 28 | 'id' => '2', |
||
| 29 | 'email' => '[email protected]', |
||
| 30 | 'firstName' => 'Jane', |
||
| 31 | 'lastName' => 'Doe' |
||
| 32 | ]), |
||
| 33 | '3' => new User([ |
||
| 34 | 'id' => '3', |
||
| 35 | 'email' => '[email protected]', |
||
| 36 | 'firstName' => 'John', |
||
| 37 | 'lastName' => 'Doe' |
||
| 38 | ]), |
||
| 39 | ]; |
||
| 40 | |||
| 41 | self::$stories = [ |
||
| 42 | '1' => new Story(['id' => '1', 'authorId' => '1', 'body' => '<h1>GraphQL is awesome!</h1>']), |
||
| 43 | '2' => new Story(['id' => '2', 'authorId' => '1', 'body' => '<a>Test this</a>']), |
||
| 44 | '3' => new Story(['id' => '3', 'authorId' => '3', 'body' => "This\n<br>story\n<br>spans\n<br>newlines"]), |
||
| 45 | ]; |
||
| 46 | |||
| 47 | self::$storyLikes = [ |
||
| 48 | '1' => ['1', '2', '3'], |
||
| 49 | '2' => [], |
||
| 50 | '3' => ['1'] |
||
| 51 | ]; |
||
| 52 | |||
| 53 | self::$comments = [ |
||
| 54 | // thread #1: |
||
| 55 | '100' => new Comment(['id' => '100', 'authorId' => '3', 'storyId' => '1', 'body' => 'Likes']), |
||
| 56 | '110' => new Comment(['id' =>'110', 'authorId' =>'2', 'storyId' => '1', 'body' => 'Reply <b>#1</b>', 'parentId' => '100']), |
||
| 57 | '111' => new Comment(['id' => '111', 'authorId' => '1', 'storyId' => '1', 'body' => 'Reply #1-1', 'parentId' => '110']), |
||
| 58 | '112' => new Comment(['id' => '112', 'authorId' => '3', 'storyId' => '1', 'body' => 'Reply #1-2', 'parentId' => '110']), |
||
| 59 | '113' => new Comment(['id' => '113', 'authorId' => '2', 'storyId' => '1', 'body' => 'Reply #1-3', 'parentId' => '110']), |
||
| 60 | '114' => new Comment(['id' => '114', 'authorId' => '1', 'storyId' => '1', 'body' => 'Reply #1-4', 'parentId' => '110']), |
||
| 61 | '115' => new Comment(['id' => '115', 'authorId' => '3', 'storyId' => '1', 'body' => 'Reply #1-5', 'parentId' => '110']), |
||
| 62 | '116' => new Comment(['id' => '116', 'authorId' => '1', 'storyId' => '1', 'body' => 'Reply #1-6', 'parentId' => '110']), |
||
| 63 | '117' => new Comment(['id' => '117', 'authorId' => '2', 'storyId' => '1', 'body' => 'Reply #1-7', 'parentId' => '110']), |
||
| 64 | '120' => new Comment(['id' => '120', 'authorId' => '3', 'storyId' => '1', 'body' => 'Reply #2', 'parentId' => '100']), |
||
| 65 | '130' => new Comment(['id' => '130', 'authorId' => '3', 'storyId' => '1', 'body' => 'Reply #3', 'parentId' => '100']), |
||
| 66 | '200' => new Comment(['id' => '200', 'authorId' => '2', 'storyId' => '1', 'body' => 'Me2']), |
||
| 67 | '300' => new Comment(['id' => '300', 'authorId' => '3', 'storyId' => '1', 'body' => 'U2']), |
||
| 68 | |||
| 69 | # thread #2: |
||
| 70 | '400' => new Comment(['id' => '400', 'authorId' => '2', 'storyId' => '2', 'body' => 'Me too']), |
||
| 71 | '500' => new Comment(['id' => '500', 'authorId' => '2', 'storyId' => '2', 'body' => 'Nice!']), |
||
| 72 | ]; |
||
| 73 | |||
| 74 | self::$storyComments = [ |
||
| 75 | '1' => ['100', '200', '300'], |
||
| 76 | '2' => ['400', '500'] |
||
| 77 | ]; |
||
| 78 | |||
| 79 | self::$commentReplies = [ |
||
| 80 | '100' => ['110', '120', '130'], |
||
| 81 | '110' => ['111', '112', '113', '114', '115', '116', '117'], |
||
| 82 | ]; |
||
| 83 | |||
| 84 | self::$storyMentions = [ |
||
| 85 | '1' => [ |
||
| 86 | self::$users['2'] |
||
| 87 | ], |
||
| 88 | '2' => [ |
||
| 89 | self::$stories['1'], |
||
| 90 | self::$users['3'] |
||
| 91 | ] |
||
| 203 |