Conditions | 2 |
Paths | 2 |
Total Lines | 71 |
Code Lines | 40 |
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 |
||
71 | public function testFactoryPackage() |
||
72 | { |
||
73 | // Create an event ticket |
||
74 | $pass = new EventTicket(time(), 'The Beat Goes On'); |
||
75 | $pass->setBackgroundColor('rgb(60, 65, 76)'); |
||
76 | $pass->setLogoText('Apple Inc.'); |
||
77 | |||
78 | // Create pass structure |
||
79 | // $structure = new PassFields(); |
||
80 | $structure = new Structure(); |
||
|
|||
81 | |||
82 | // Add primary field |
||
83 | $primary = new Field('event', 'The Beat Goes On'); |
||
84 | $primary->setLabel('Event'); |
||
85 | $structure->addPrimaryField($primary); |
||
86 | |||
87 | // Add secondary field |
||
88 | $secondary = new Field('location', 'Moscone West'); |
||
89 | $secondary->setLabel('Location'); |
||
90 | $structure->addSecondaryField($secondary); |
||
91 | |||
92 | // Add auxiliary field |
||
93 | $auxiliary = new Field('datetime', '2013-04-15 @10:25'); |
||
94 | $auxiliary->setLabel('Date & Time'); |
||
95 | $structure->addAuxiliaryField($auxiliary); |
||
96 | |||
97 | $auxiliary = new NumberField('price', '12.34'); |
||
98 | $auxiliary->setLabel('Price'); |
||
99 | $auxiliary->setCurrencyCode('USD'); |
||
100 | $structure->addAuxiliaryField($auxiliary); |
||
101 | |||
102 | // Add icon image |
||
103 | $icon = new Image(__DIR__ . '/../../img/icon.png', 'icon'); |
||
104 | $pass->addImage($icon); |
||
105 | |||
106 | // Set pass structure |
||
107 | $pass->setStructure($structure); |
||
108 | |||
109 | // Add barcode |
||
110 | $barcode = new Barcode(Barcode::TYPE_QR, 'barcodeMessage'); |
||
111 | $pass->setBarcode($barcode); |
||
112 | |||
113 | // Add Localizations (this also tests zipping subdirectories) |
||
114 | $englishText = [ |
||
115 | 'created_by' => 'Pass produced by php-passbook' |
||
116 | ]; |
||
117 | |||
118 | $spanishText = [ |
||
119 | 'created_by' => 'Pase producido por php-passbook' |
||
120 | ]; |
||
121 | |||
122 | $es = new Localization('es'); |
||
123 | $es->addStrings($spanishText); |
||
124 | $pass->addLocalization($es); |
||
125 | |||
126 | $en = new Localization('en'); |
||
127 | $en->addStrings($englishText); |
||
128 | $pass->addLocalization($en); |
||
129 | |||
130 | $field = new Field('exclusive_card', 'created_by'); |
||
131 | $structure->addBackField($field); |
||
132 | |||
133 | if ($this->skipPackageTest) { |
||
134 | $this->markTestIncomplete( |
||
135 | 'P12 and/or WWDR certificate(s) not found' |
||
136 | ); |
||
137 | } |
||
138 | |||
139 | $this->factory->setOutputPath(__DIR__ . '/../../../www/passes'); |
||
140 | $file = $this->factory->package($pass); |
||
141 | $this->assertInstanceOf('SplFileObject', $file); |
||
142 | } |
||
236 |