Completed
Push — symfony3 ( 06e2ee...17e915 )
by Kamil
46:11 queued 26:57
created

ProductVariantsParityChecker   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B checkParity() 0 15 5
A matchOptions() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Product\Checker;
13
14
use Sylius\Component\Product\Model\ProductInterface;
15
use Sylius\Component\Product\Model\ProductVariantInterface;
16
use Webmozart\Assert\Assert;
17
18
/**
19
 * @author Łukasz Chruściel <[email protected]>
20
 */
21
final class ProductVariantsParityChecker implements ProductVariantsParityCheckerInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function checkParity(ProductVariantInterface $variant, ProductInterface $product)
27
    {
28
        foreach ($product->getVariants() as $existingVariant) {
29
            // This check is require, because this function has to look for any other different variant with same option values set
30
            if ($variant === $existingVariant || count($variant->getOptionValues()) !== count($product->getOptions())) {
31
                continue;
32
            }
33
34
            if ($this->matchOptions($variant, $existingVariant)) {
35
                return true;
36
            }
37
        }
38
39
        return false;
40
    }
41
42
    /**
43
     * @param ProductVariantInterface $variant
44
     * @param ProductVariantInterface $existingVariant
45
     *
46
     * @return bool
47
     */
48
    private function matchOptions(ProductVariantInterface $variant, ProductVariantInterface $existingVariant)
0 ignored issues
show
Coding Style introduced by
function matchOptions() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
49
    {
50
        foreach ($variant->getOptionValues() as $option) {
51
            if (!$existingVariant->hasOptionValue($option)) {
52
               return false;
53
            }
54
        }
55
56
        return true;
57
    }
58
}
59