Passed
Push — master ( 101cf0...6b8c52 )
by Mikołaj
04:53
created

it_returns_null_when_product_doeas_not_have_any_variant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 8
dl 0
loc 16
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product;
14
15
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
18
use Sylius\Component\Channel\Context\ChannelContextInterface;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
use Sylius\Component\Core\Model\ChannelPricingInterface;
21
use Sylius\Component\Core\Model\ProductInterface;
22
use Sylius\Component\Core\Model\ProductVariantInterface;
23
use Sylius\Component\Currency\Model\CurrencyInterface;
24
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
25
26
final class ChannelPricingTransformerSpec extends ObjectBehavior
27
{
28
    function let(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
        ChannelContextInterface $channelContext,
30
        ProductVariantResolverInterface $productVariantResolver,
31
        MoneyFormatterInterface $moneyFormatter
32
    ): void {
33
        $this->beConstructedWith($channelContext, $productVariantResolver, $moneyFormatter);
34
    }
35
36
    function it_is_a_transformer(): void
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
    {
38
        $this->shouldImplement(TransformerInterface::class);
39
    }
40
41
    function it_transforms_product_channel_prices_into_formatted_price(
42
        ChannelContextInterface $channelContext,
43
        ProductVariantResolverInterface $productVariantResolver,
44
        MoneyFormatterInterface $moneyFormatter,
45
        CurrencyInterface $currency,
46
        ChannelInterface $channel,
47
        ProductVariantInterface $productVariant,
48
        ProductInterface $product,
49
        ChannelPricingInterface $channelPricing
50
    ): void {
51
        $currency->getCode()->willReturn('USD');
52
        $channel->getBaseCurrency()->willReturn($currency);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Currency\Model\CurrencyInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $channel->getBaseCurrency()->/** @scrutinizer ignore-call */ willReturn($currency);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        $channelContext->getChannel()->willReturn($channel);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Channel\Model\ChannelInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $channelContext->getChannel()->/** @scrutinizer ignore-call */ willReturn($channel);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $productVariantResolver->getVariant($product)->willReturn($productVariant);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Product...ProductVariantInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $productVariantResolver->getVariant($product)->/** @scrutinizer ignore-call */ willReturn($productVariant);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        $channelPricing->getPrice()->willReturn(10);
56
        $productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Core\Mo...ChannelPricingInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $productVariant->getChannelPricingForChannel($channel)->/** @scrutinizer ignore-call */ willReturn($channelPricing);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
        $moneyFormatter->format(10, 'USD');
59
60
        $this->transform($product);
0 ignored issues
show
Bug introduced by
The method transform() does not exist on spec\BitBag\SyliusElasti...lPricingTransformerSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $this->/** @scrutinizer ignore-call */ 
61
               transform($product);
Loading history...
61
    }
62
63
    function it_returns_null_when_product_doeas_not_have_any_variant(
64
        ChannelContextInterface $channelContext,
65
        ProductVariantResolverInterface $productVariantResolver,
66
        MoneyFormatterInterface $moneyFormatter,
0 ignored issues
show
Unused Code introduced by
The parameter $moneyFormatter is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
        /** @scrutinizer ignore-unused */ MoneyFormatterInterface $moneyFormatter,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
        CurrencyInterface $currency,
68
        ChannelInterface $channel,
69
        ProductVariantInterface $productVariant,
0 ignored issues
show
Unused Code introduced by
The parameter $productVariant is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
        /** @scrutinizer ignore-unused */ ProductVariantInterface $productVariant,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
        ProductInterface $product,
71
        ChannelPricingInterface $channelPricing
0 ignored issues
show
Unused Code introduced by
The parameter $channelPricing is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

71
        /** @scrutinizer ignore-unused */ ChannelPricingInterface $channelPricing

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    ): void {
73
        $currency->getCode()->willReturn('USD');
74
        $channel->getBaseCurrency()->willReturn($currency);
75
        $channelContext->getChannel()->willReturn($channel);
76
        $productVariantResolver->getVariant($product)->willReturn(null);
77
78
        $this->transform($product)->shouldBeNull();
79
    }
80
}
81