| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 75 | protected function setUp() |
||
| 76 | { |
||
| 77 | $this->objectManager = new ObjectManager($this); |
||
| 78 | |||
| 79 | $redirectResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); |
||
| 80 | |||
| 81 | $redirect = $this->getMockBuilder(RedirectResponse::class)->disableOriginalConstructor()->getMock(); |
||
| 82 | $redirect->method('redirect')->willReturn($redirectResponse); |
||
| 83 | |||
| 84 | $response = $this->getMockBuilder(Response::class) |
||
| 85 | ->disableOriginalConstructor() |
||
| 86 | ->setMethods(['setRedirect']) |
||
| 87 | ->getMock(); |
||
| 88 | |||
| 89 | $url = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock(); |
||
| 90 | |||
| 91 | $this->request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->setMethods(['getBeforeForwardInfo'])->getMock(); |
||
| 92 | |||
| 93 | $messageManager = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); |
||
| 94 | |||
| 95 | $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
||
| 96 | $context->method('getRedirect')->willReturn($redirect); |
||
| 97 | $context->method('getRequest')->willReturn($this->request); |
||
| 98 | $context->method('getResponse')->willReturn($response); |
||
| 99 | $context->method('getUrl')->willReturn($url); |
||
| 100 | $context->method('getMessageManager')->willReturn($messageManager); |
||
| 101 | |||
| 102 | $address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
||
| 103 | |||
| 104 | $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
||
| 105 | $quote->method('getBillingAddress')->willReturn($address); |
||
| 106 | $quote->method('getShippingAddress')->willReturn($address); |
||
| 107 | $quote->method('getIsVirtual')->willReturn(false); |
||
| 108 | $quote->method('getId')->willReturn('12345'); |
||
| 109 | $quote->method('setIsActive')->willReturn($quote); |
||
| 110 | |||
| 111 | $this->checkoutSession = $this->getMockBuilder(Session::class) |
||
| 112 | ->disableOriginalConstructor() |
||
| 113 | ->setMethods(['getQuote', 'setLastQuoteId', 'setLastSuccessQuoteId', 'unsPayoneWorkorderId']) |
||
| 114 | ->getMock(); |
||
| 115 | $this->checkoutSession->method('getQuote')->willReturn($quote); |
||
| 116 | $this->checkoutSession->method('setLastQuoteId')->willReturn($this->checkoutSession); |
||
| 117 | $this->checkoutSession->method('setLastSuccessQuoteId')->willReturn($this->checkoutSession); |
||
| 118 | |||
| 119 | $this->agreementValidator = $this->getMockBuilder(AgreementsValidatorInterface::class)->disableOriginalConstructor()->getMock(); |
||
| 120 | $this->agreementValidator->method('isValid')->willReturn(false); |
||
| 121 | |||
| 122 | $this->cartManagement = $this->getMockBuilder(CartManagementInterface::class)->disableOriginalConstructor()->getMock(); |
||
| 123 | |||
| 124 | $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
||
| 125 | 'context' => $context, |
||
| 126 | 'checkoutSession' => $this->checkoutSession, |
||
| 127 | 'agreementValidator' => $this->agreementValidator, |
||
| 128 | 'cartManagement' => $this->cartManagement |
||
| 129 | ]); |
||
| 130 | } |
||
| 131 | |||
| 156 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.