| Conditions | 2 |
| Paths | 2 |
| Total Lines | 117 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | private function getExceptedSchemaContainer() |
||
| 24 | { |
||
| 25 | if (self::$expectedSchema !== null) { |
||
| 26 | return self::$expectedSchema; |
||
| 27 | } |
||
| 28 | |||
| 29 | $episodeType = new Type(); |
||
| 30 | $episodeType |
||
| 31 | ->setName('Episode') |
||
| 32 | ->setDescription('One of the films in the Star Wars Trilogy') |
||
| 33 | ->setValues([ |
||
| 34 | 'NEWHOPE' => [ |
||
| 35 | 'value' => 4, |
||
| 36 | 'description' => 'Released in 1977.', |
||
| 37 | ], |
||
| 38 | 'EMPIRE' => [ |
||
| 39 | 'value' => 5, |
||
| 40 | 'description' => 'Released in 1980.', |
||
| 41 | ], |
||
| 42 | 'JEDI' => [ |
||
| 43 | 'value' => 6, |
||
| 44 | 'description' => 'Released in 1983.', |
||
| 45 | ], |
||
| 46 | ]); |
||
| 47 | |||
| 48 | $characterInterface = new InterfaceType(); |
||
| 49 | $characterInterface |
||
| 50 | ->setName('Character') |
||
| 51 | ->setDescription('A character in the Star Wars Trilogy') |
||
| 52 | ->setFields([ |
||
| 53 | $this->createIdField('The id of the character.'), |
||
| 54 | $this->createNameField('The name of the character.'), |
||
| 55 | $this->createFriendsField('The friends of the character, or an empty list if they have none.'), |
||
| 56 | $this->createAppearsInField(), |
||
| 57 | ]); |
||
| 58 | |||
| 59 | $homePlanet = new Field(); |
||
| 60 | $homePlanet |
||
| 61 | ->setName('homePlanet') |
||
| 62 | ->setType('String') |
||
| 63 | ->setDescription('The home planet of the human, or null if unknown.'); |
||
| 64 | |||
| 65 | $humanType = new Type(); |
||
| 66 | $humanType->setName('Human') |
||
| 67 | ->setDescription('A humanoid creature in the Star Wars universe.') |
||
| 68 | ->setExtends('Character') |
||
| 69 | ->setFields([ |
||
| 70 | $this->createIdField('The id of the human.'), |
||
| 71 | $this->createNameField('The name of the human.'), |
||
| 72 | $this->createFriendsField('The friends of the human, or an empty list if they have none.'), |
||
| 73 | $this->createAppearsInField(), |
||
| 74 | $homePlanet |
||
| 75 | ]); |
||
| 76 | |||
| 77 | $primaryFunction = new Field(); |
||
| 78 | $primaryFunction |
||
| 79 | ->setName('primaryFunction') |
||
| 80 | ->setType('String') |
||
| 81 | ->setDescription('The primary function of the droid.'); |
||
| 82 | |||
| 83 | $droidType = new Type(); |
||
| 84 | $droidType->setName('Droid') |
||
| 85 | ->setDescription('A mechanical creature in the Star Wars universe.') |
||
| 86 | ->setExtends('Character') |
||
| 87 | ->setFields([ |
||
| 88 | $this->createIdField('The id of the droid.'), |
||
| 89 | $this->createNameField('The name of the droid.'), |
||
| 90 | $this->createFriendsField('The friends of the droid, or an empty list if they have none.'), |
||
| 91 | $this->createAppearsInField(), |
||
| 92 | $primaryFunction |
||
| 93 | ]); |
||
| 94 | |||
| 95 | $episodeField = new Field(); |
||
| 96 | $episodeField |
||
| 97 | ->setName('episode') |
||
| 98 | ->setType('Episode') |
||
| 99 | ->setDescription('If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.'); |
||
| 100 | |||
| 101 | $heroField = new Field(); |
||
| 102 | $heroField->setName('hero') |
||
| 103 | ->setType('Character') |
||
| 104 | ->setArguments([ |
||
| 105 | $episodeField, |
||
| 106 | ]); |
||
| 107 | |||
| 108 | $humanField = new Field(); |
||
| 109 | $humanField->setName('human') |
||
| 110 | ->setType('Human') |
||
| 111 | ->setArguments([ |
||
| 112 | $this->createIdField('id of the human'), |
||
| 113 | ]); |
||
| 114 | |||
| 115 | $droidField = new Field(); |
||
| 116 | $droidField->setName('droid') |
||
| 117 | ->setType('Droid') |
||
| 118 | ->setArguments([ |
||
| 119 | $this->createIdField('id of the droid'), |
||
| 120 | ]); |
||
| 121 | |||
| 122 | $query = new Query(); |
||
| 123 | $query |
||
| 124 | ->setFields([ |
||
| 125 | $heroField, |
||
| 126 | $humanField, |
||
| 127 | $droidField, |
||
| 128 | ]); |
||
| 129 | |||
| 130 | $schema = new SchemaContainer(); |
||
| 131 | $schema |
||
| 132 | ->addType($episodeType) |
||
| 133 | ->addType($humanType) |
||
| 134 | ->addType($droidType) |
||
| 135 | ->addInterface($characterInterface) |
||
| 136 | ->setQuerySchema($query); |
||
| 137 | |||
| 138 | return self::$expectedSchema = $schema; |
||
| 139 | } |
||
| 140 | |||
| 185 |