| Conditions | 2 |
| Paths | 2 |
| Total Lines | 71 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 41 | public function testFactoryPackage() |
||
| 42 | { |
||
| 43 | if ($this->skipPackageTest) { |
||
| 44 | $this->markTestSkipped( |
||
| 45 | 'P12 and/or WWDR certificate(s) not found' |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Create an event ticket |
||
| 50 | $pass = new EventTicket(time(), 'The Beat Goes On'); |
||
| 51 | $pass->setBackgroundColor('rgb(60, 65, 76)'); |
||
| 52 | $pass->setLogoText('Apple Inc.'); |
||
| 53 | |||
| 54 | // Create pass structure |
||
| 55 | $structure = new Structure(); |
||
| 56 | |||
| 57 | // Add primary field |
||
| 58 | $primary = new Field('event', 'The Beat Goes On'); |
||
| 59 | $primary->setLabel('Event'); |
||
| 60 | $structure->addPrimaryField($primary); |
||
| 61 | |||
| 62 | // Add secondary field |
||
| 63 | $secondary = new Field('location', 'Moscone West'); |
||
| 64 | $secondary->setLabel('Location'); |
||
| 65 | $structure->addSecondaryField($secondary); |
||
| 66 | |||
| 67 | // Add auxiliary field |
||
| 68 | $auxiliary = new Field('datetime', '2013-04-15 @10:25'); |
||
| 69 | $auxiliary->setLabel('Date & Time'); |
||
| 70 | $structure->addAuxiliaryField($auxiliary); |
||
| 71 | |||
| 72 | $auxiliary = new Pass\NumberField('price', '12.34'); |
||
| 73 | $auxiliary->setLabel('Price'); |
||
| 74 | $auxiliary->setCurrencyCode('USD'); |
||
| 75 | $structure->addAuxiliaryField($auxiliary); |
||
| 76 | |||
| 77 | // Add icon image |
||
| 78 | $icon = new Image(__DIR__.'/../../img/icon.png', 'icon'); |
||
| 79 | $pass->addImage($icon); |
||
| 80 | |||
| 81 | // Set pass structure |
||
| 82 | $pass->setStructure($structure); |
||
| 83 | |||
| 84 | // Add barcode |
||
| 85 | $barcode = new Barcode(Barcode::TYPE_QR, 'barcodeMessage'); |
||
| 86 | $pass->setBarcode($barcode); |
||
| 87 | |||
| 88 | // Add Localizations (this also tests zipping subdirectories) |
||
| 89 | $englishText = array( |
||
| 90 | 'created_by' => 'Pass produced by php-passbook' |
||
| 91 | ); |
||
| 92 | |||
| 93 | $spanishText = array( |
||
| 94 | 'created_by' => 'Pase producido por php-passbook' |
||
| 95 | ); |
||
| 96 | |||
| 97 | $es = new Localization('es'); |
||
| 98 | $es->addStrings($spanishText); |
||
| 99 | $pass->addLocalization($es); |
||
| 100 | |||
| 101 | $en = new Localization('en'); |
||
| 102 | $en->addStrings($englishText); |
||
| 103 | $pass->addLocalization($en); |
||
| 104 | |||
| 105 | $field = new Field('exclusive_card', 'created_by'); |
||
| 106 | $structure->addBackField($field); |
||
| 107 | |||
| 108 | $this->factory->setOutputPath(__DIR__.'/../../../www/passes'); |
||
| 109 | $file = $this->factory->package($pass); |
||
| 110 | $this->assertInstanceOf('SplFileObject', $file); |
||
| 111 | } |
||
| 112 | |||
| 198 |