Completed
Push — master ( eeff33...1702a2 )
by Kamil
41:57 queued 20:40
created

AddressingContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createNewAddress() 0 6 1
A createAddress() 0 19 1
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\Behat\Context\Transform;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Addressing\Converter\CountryNameConverterInterface;
16
use Sylius\Component\Addressing\Model\CountryInterface;
17
use Sylius\Component\Core\Model\AddressInterface;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
21
/**
22
 * @author Łukasz Chruściel <[email protected]>
23
 */
24
final class AddressingContext implements Context
25
{
26
    /**
27
     * @var FactoryInterface
28
     */
29
    private $addressFactory;
30
31
    /**
32
     * @var CountryNameConverterInterface
33
     */
34
    private $countryNameConverter;
35
36
    /**
37
     * @param FactoryInterface $addressFactory
38
     * @param CountryNameConverterInterface $countryNameConverter
39
     */
40
    public function __construct(FactoryInterface $addressFactory, CountryNameConverterInterface $countryNameConverter)
41
    {
42
        $this->addressFactory = $addressFactory;
43
        $this->countryNameConverter = $countryNameConverter;
44
    }
45
46
    /**
47
     * @Transform /^to "([^"]+)"$/
48
     */
49
    public function createNewAddress($countryName)
50
    {
51
        $countryCode = $this->countryNameConverter->convertToCode($countryName);
52
53
        return $this->createAddress($countryCode);
54
    }
55
56
    /**
57
     * @param string $countryCode
58
     * @param string $firstName
59
     * @param string $lastName
60
     * @param string $city
61
     * @param string $street
62
     *
63
     * @return AddressInterface
64
     */
65
    private function createAddress(
66
        $countryCode = 'FR',
67
        $firstName = 'John',
68
        $lastName = 'Doe',
69
        $city = 'Ankh Morpork',
70
        $street = 'Frost Alley',
71
        $postCode = '90210'
72
    ) {
73
        /** @var AddressInterface $address */
74
        $address = $this->addressFactory->createNew();
75
        $address->setCountryCode($countryCode);
76
        $address->setFirstName($firstName);
77
        $address->setLastName($lastName);
78
        $address->setCity($city);
79
        $address->setStreet($street);
80
        $address->setPostcode($postCode);
81
82
        return $address;
83
    }
84
}
85