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