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