Conditions | 11 |
Paths | 4 |
Total Lines | 38 |
Code Lines | 25 |
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 |
||
28 | public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
||
29 | { |
||
30 | $Order = $itemHolder; |
||
31 | |||
32 | if ($Order instanceof \Eccube\Entity\Order) { |
||
33 | if ($Order->getCode() == "") { |
||
34 | if (is_null($Order->getId())) { |
||
35 | $this->entityManager->persist($Order); |
||
36 | $this->entityManager->flush(); |
||
37 | } |
||
38 | |||
39 | $orderCode = preg_replace_callback('/\${(.*)}/U', function($matches) use ($Order) { |
||
40 | if (count($matches) == 2) { |
||
41 | switch ($matches[1]) { |
||
42 | case "yyyy": |
||
43 | return date('Y'); |
||
44 | case "mm": |
||
45 | return date('m'); |
||
46 | case "dd": |
||
47 | return date('d'); |
||
48 | default: |
||
49 | $no = explode(',', $matches[1]); |
||
50 | if (count($no) == 2 && $no[0] == 'number' && is_numeric($no[1])) { |
||
51 | return sprintf("%0{$no[1]}d", $Order->getId()); |
||
52 | } |
||
53 | return ""; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | return ""; |
||
58 | }, $this->orderNoFormat); |
||
59 | |||
60 | $Order->setCode($orderCode); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | return ProcessResult::success(); |
||
65 | } |
||
66 | } |