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