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\Core\Test\Services; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
15
|
|
|
use Sylius\Component\Addressing\Model\ZoneMemberInterface; |
16
|
|
|
use Sylius\Component\Channel\Factory\ChannelFactoryInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class DefaultFranceChannelFactory implements DefaultStoreDataInterface |
25
|
|
|
{ |
26
|
|
|
const DEFAULT_CHANNEL_CODE = 'WEB-FR'; |
27
|
|
|
const DEFAULT_ZONE_CODE = 'FR'; |
28
|
|
|
const DEFAULT_ZONE_NAME = 'France'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var RepositoryInterface |
32
|
|
|
*/ |
33
|
|
|
private $channelRepository; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var RepositoryInterface |
37
|
|
|
*/ |
38
|
|
|
private $zoneMemberRepository; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var RepositoryInterface |
42
|
|
|
*/ |
43
|
|
|
private $zoneRepository; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ChannelFactoryInterface |
47
|
|
|
*/ |
48
|
|
|
private $channelFactory; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var FactoryInterface |
52
|
|
|
*/ |
53
|
|
|
private $zoneMemberFactory; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var FactoryInterface |
57
|
|
|
*/ |
58
|
|
|
private $zoneFactory; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param RepositoryInterface $channelRepository |
62
|
|
|
* @param RepositoryInterface $zoneMemberRepository |
63
|
|
|
* @param RepositoryInterface $zoneRepository |
64
|
|
|
* @param FactoryInterface $channelFactory |
65
|
|
|
* @param FactoryInterface $zoneMemberFactory |
66
|
|
|
* @param FactoryInterface $zoneFactory |
67
|
|
|
*/ |
68
|
|
|
public function __construct( |
69
|
|
|
RepositoryInterface $channelRepository, |
70
|
|
|
RepositoryInterface $zoneMemberRepository, |
71
|
|
|
RepositoryInterface $zoneRepository, |
72
|
|
|
FactoryInterface $channelFactory, |
73
|
|
|
FactoryInterface $zoneMemberFactory, |
74
|
|
|
FactoryInterface $zoneFactory |
75
|
|
|
) { |
76
|
|
|
$this->channelRepository = $channelRepository; |
77
|
|
|
$this->zoneMemberRepository = $zoneMemberRepository; |
78
|
|
|
$this->zoneRepository = $zoneRepository; |
79
|
|
|
$this->channelFactory = $channelFactory; |
|
|
|
|
80
|
|
|
$this->zoneMemberFactory = $zoneMemberFactory; |
81
|
|
|
$this->zoneFactory = $zoneFactory; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function create() |
88
|
|
|
{ |
89
|
|
|
$defaultData['channel'] = $this->createChannel(); |
|
|
|
|
90
|
|
|
$defaultData['zone_member'] = $this->createZoneMember(); |
91
|
|
|
$defaultData['zone'] = $this->createZone($defaultData['zone_member']); |
92
|
|
|
|
93
|
|
|
$this->channelRepository->add($defaultData['channel']); |
94
|
|
|
$this->zoneRepository->add($defaultData['zone']); |
95
|
|
|
$this->zoneMemberRepository->add($defaultData['zone_member']); |
96
|
|
|
|
97
|
|
|
return $defaultData; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return ChannelInterface |
102
|
|
|
*/ |
103
|
|
|
private function createChannel() |
104
|
|
|
{ |
105
|
|
|
$channel = $this->channelFactory->createNamed('France'); |
106
|
|
|
$channel->setCode(self::DEFAULT_CHANNEL_CODE); |
107
|
|
|
|
108
|
|
|
return $channel; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return ZoneMemberInterface |
113
|
|
|
*/ |
114
|
|
|
private function createZoneMember() |
115
|
|
|
{ |
116
|
|
|
$zoneMember = $this->zoneMemberFactory->createNew(); |
117
|
|
|
$zoneMember->setCode(self::DEFAULT_ZONE_CODE); |
118
|
|
|
|
119
|
|
|
return $zoneMember; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param ZoneMemberInterface $zoneMember |
124
|
|
|
* |
125
|
|
|
* @return ZoneInterface |
126
|
|
|
*/ |
127
|
|
|
private function createZone(ZoneMemberInterface $zoneMember) |
128
|
|
|
{ |
129
|
|
|
$zone = $this->zoneFactory->createNew(); |
130
|
|
|
$zone->setCode(self::DEFAULT_ZONE_CODE); |
131
|
|
|
$zone->setName(self::DEFAULT_ZONE_NAME); |
132
|
|
|
$zone->setType(ZoneInterface::TYPE_COUNTRY); |
133
|
|
|
$zone->addMember($zoneMember); |
134
|
|
|
|
135
|
|
|
return $zone; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.