Conditions | 30 |
Paths | 2366 |
Total Lines | 89 |
Code Lines | 75 |
Lines | 33 |
Ratio | 37.08 % |
Changes | 1 | ||
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 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
42 | |||
43 | $locale = $input->getOption('with-locale'); |
||
44 | $imageType = $input->getOption('with-image'); |
||
45 | $notImage = $input->getOption('without-image'); |
||
46 | $numberOfProducts = $input->getOption('products'); |
||
47 | $numberOfOrder = $input->getOption('orders'); |
||
48 | $numberOfCustomer = $input->getOption('customers'); |
||
49 | |||
50 | $this->app = $this->getSilexApplication(); |
||
51 | $this->app->register(new \Eccube\Tests\ServiceProvider\FixtureServiceProvider()); |
||
52 | $Customers = []; |
||
53 | $Products = []; |
||
54 | |||
55 | $faker = Faker::create($locale); |
||
56 | for ($i = 0; $i < $numberOfCustomer; $i++) { |
||
57 | $email = microtime(true).'.'.$faker->safeEmail; |
||
58 | $Customer = $this->app['eccube.fixture.generator.locale']($locale)->createCustomer($email); |
||
59 | $Customer->setBirth($faker->dateTimeBetween('-110 years', '- 5 years')); |
||
60 | View Code Duplication | switch ($output->getVerbosity()) { |
|
61 | case OutputInterface::VERBOSITY_QUIET: |
||
62 | break; |
||
63 | case OutputInterface::VERBOSITY_NORMAL: |
||
64 | $output->write('C'); |
||
65 | break; |
||
66 | case OutputInterface::VERBOSITY_VERBOSE: |
||
67 | case OutputInterface::VERBOSITY_VERY_VERBOSE: |
||
68 | case OutputInterface::VERBOSITY_DEBUG: |
||
69 | $output->writeln('Customer: id='.$Customer->getId().' '.$Customer->getEmail()); |
||
70 | break; |
||
71 | } |
||
72 | View Code Duplication | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL && ($i % 100) === 0 && $i > 0) { |
|
73 | $output->writeln(' ...'.$i); |
||
74 | } |
||
75 | $Customers[] = $Customer; |
||
76 | } |
||
77 | for ($i = 0; $i < $numberOfProducts; $i++) { |
||
78 | $Product = $this->app['eccube.fixture.generator.locale']($locale)->createProduct(null, 3, $notImage ? null : $imageType); |
||
79 | View Code Duplication | switch ($output->getVerbosity()) { |
|
80 | case OutputInterface::VERBOSITY_QUIET: |
||
81 | break; |
||
82 | case OutputInterface::VERBOSITY_NORMAL: |
||
83 | $output->write('P'); |
||
84 | break; |
||
85 | case OutputInterface::VERBOSITY_VERBOSE: |
||
86 | case OutputInterface::VERBOSITY_VERY_VERBOSE: |
||
87 | case OutputInterface::VERBOSITY_DEBUG: |
||
88 | $output->writeln('Product: id='.$Product->getId().' '.$Product->getName()); |
||
89 | break; |
||
90 | } |
||
91 | View Code Duplication | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL && ($i % 100) === 0 && $i > 0) { |
|
92 | $output->writeln(' ...'.$i); |
||
93 | } |
||
94 | $Products[] = $Product; |
||
95 | } |
||
96 | $Deliveries = $this->app['eccube.repository.delivery']->findAll(); |
||
97 | $j = 0; |
||
98 | foreach ($Customers as $Customer) { |
||
99 | $Delivery = $Deliveries[$faker->numberBetween(0, count($Deliveries) - 1)]; |
||
100 | $Product = $Products[$faker->numberBetween(0, $numberOfProducts - 1)]; |
||
101 | $charge = $faker->randomNumber(4); |
||
102 | $discount = $faker->randomNumber(4); |
||
103 | for ($i = 0; $i < $numberOfOrder; $i++) { |
||
104 | $Order = $this->app['eccube.fixture.generator.locale']($locale)->createOrder($Customer, $Product->getProductClasses()->toArray(), $Delivery, $charge, $discount); |
||
105 | $Status = $this->app['eccube.repository.order_status']->find($faker->numberBetween(1, 8)); |
||
106 | $Order->setOrderStatus($Status); |
||
107 | $Order->setOrderDate($faker->dateTimeThisYear()); |
||
108 | switch ($output->getVerbosity()) { |
||
109 | case OutputInterface::VERBOSITY_QUIET: |
||
110 | break; |
||
111 | case OutputInterface::VERBOSITY_NORMAL: |
||
112 | $output->write('O'); |
||
113 | break; |
||
114 | case OutputInterface::VERBOSITY_VERBOSE: |
||
115 | case OutputInterface::VERBOSITY_VERY_VERBOSE: |
||
116 | case OutputInterface::VERBOSITY_DEBUG: |
||
117 | $output->writeln('Order: id='.$Order->getId()); |
||
118 | break; |
||
119 | } |
||
120 | $this->app['orm.em']->flush($Order); |
||
121 | $j++; |
||
122 | View Code Duplication | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL && ($j % 100) === 0 && $j > 0) { |
|
123 | $output->writeln(' ...'.$j); |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | $output->writeln(''); |
||
128 | $output->writeln(sprintf("%s <info>success</info>", 'dummydata:generate')); |
||
129 | } |
||
130 | } |
||
131 |