| Conditions | 6 |
| Paths | 7 |
| Total Lines | 64 |
| Code Lines | 46 |
| 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 |
||
| 50 | { |
||
| 51 | $path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'supplier.php'; |
||
| 52 | |||
| 53 | if( ( $testdata = include( $path ) ) == false ) { |
||
| 54 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for supplier domain', $path ) ); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $testdata; |
||
| 58 | } |
||
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * Returns the manager for the current setup task |
||
| 63 | * |
||
| 64 | * @param string $domain Domain name of the manager |
||
| 65 | * @return \Aimeos\MShop\Common\Manager\Iface Manager object |
||
| 66 | */ |
||
| 67 | protected function getManager( $domain ) |
||
| 68 | { |
||
| 69 | if( $domain === 'supplier' ) { |
||
| 70 | return \Aimeos\MShop\Supplier\Manager\Factory::create( $this->additional, 'Standard' ); |
||
| 71 | } |
||
| 72 | |||
| 73 | return parent::getManager( $domain ); |
||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | /** |
||
| 78 | * Adds the supplier data from the given array |
||
| 79 | * |
||
| 80 | * @param array Multi-dimensional array of test data |
||
|
|
|||
| 81 | */ |
||
| 82 | protected function process( array $testdata ) |
||
| 83 | { |
||
| 84 | $manager = $this->getManager( 'supplier' ); |
||
| 85 | $listManager = $manager->getSubManager( 'lists' ); |
||
| 86 | $addrManager = $manager->getSubManager( 'address' ); |
||
| 87 | |||
| 88 | $manager->begin(); |
||
| 89 | $this->storeTypes( $testdata, ['supplier/lists/type'] ); |
||
| 90 | $manager->commit(); |
||
| 91 | |||
| 92 | foreach( $testdata['supplier'] ?? [] as $entry ) |
||
| 93 | { |
||
| 94 | $item = $manager->create()->fromArray( $entry ); |
||
| 95 | $item = $this->addListData( $listManager, $item, $entry ); |
||
| 96 | $item = $this->addAddressData( $addrManager, $item, $entry ); |
||
| 97 | |||
| 98 | $manager->save( $item ); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 |