Skip to content

Commit 39d2df8

Browse files
committed
Introduce common codding standart and fix inconsistencies
1 parent 22876ee commit 39d2df8

14 files changed

+78
-45
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
}
3333
},
3434
"scripts": {
35-
"phpcs": "phpcs --standard=PSR1,PSR2 src/",
36-
"phpcbf": "phpcbf --standard=PSR1,PSR2 src/",
35+
"phpcs": "phpcs",
36+
"phpcbf": "phpcbf",
3737
"phpstan": "phpstan analyze src"
3838
}
3939
}

phpcs.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Compiler">
3+
<description>The coding standard for EcomDev packages.</description>
4+
5+
<file>src</file>
6+
7+
<arg value="np"/>
8+
9+
<!-- Include some additional sniffs from the Generic standard -->
10+
<rule ref="Generic.Commenting.DocComment"/>
11+
12+
<!-- Use Unix newlines -->
13+
<rule ref="Generic.Files.LineEndings">
14+
<properties>
15+
<property name="eolChar" value="\n"/>
16+
</properties>
17+
</rule>
18+
19+
<rule ref="PSR2"/>
20+
<rule ref="PSR2"/>
21+
</ruleset>

src/DataService/CustomerGroupProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Customer group provider for dynamic resolution of it
16-
*
1716
*/
1817
class CustomerGroupProvider
1918
{

src/DataService/DataLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface DataLoader
2424
*
2525
* @param ScopeFilter $filter
2626
* @param ProductWrapper[] $products
27+
*
2728
* @return array
2829
*/
2930
public function load(ScopeFilter $filter, array $products): array;
@@ -32,6 +33,7 @@ public function load(ScopeFilter $filter, array $products): array;
3233
* Checks if the preloader is applicable for this type of data.
3334
*
3435
* @param string $type
36+
*
3537
* @return bool
3638
*/
3739
public function isApplicable(string $type): bool;

src/DataService/LoadService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
class LoadService
1414
{
1515
/**
16+
* Storage for preloaded data
17+
*
1618
* @var array
1719
*/
1820
private $storage = [];
1921

2022
/**
23+
* Mapping of SKU to ids
24+
*
2125
* @var array
2226
*/
2327
private $skuToId = [];
2428

2529
/**
30+
* List of registered data loaders by code
31+
*
2632
* @var DataLoader[]
2733
*/
2834
private $loaders;
@@ -45,6 +51,7 @@ public function __construct(array $loaders)
4551
* When SKU is not found it returns null
4652
*
4753
* @param string $sku
54+
*
4855
* @return int|null
4956
*/
5057
public function skuToId(string $sku): ?int
@@ -58,6 +65,7 @@ public function skuToId(string $sku): ?int
5865
*
5966
* @param int $productId
6067
* @param string $type
68+
*
6169
* @return bool
6270
*/
6371
public function has(int $productId, string $type): bool
@@ -70,6 +78,7 @@ public function has(int $productId, string $type): bool
7078
*
7179
* @param int $productId
7280
* @param string $type
81+
*
7382
* @return array
7483
*/
7584
public function get(int $productId, string $type): array

src/DataService/MagentoProductWrapper.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
class MagentoProductWrapper implements ProductWrapper
1515
{
1616
/**
17+
* Wrapped product model
18+
*
1719
* @var Product
1820
*/
1921
private $product;
@@ -29,41 +31,32 @@ public function __construct(Product $product)
2931
}
3032

3133
/**
32-
* Returns product SKU
33-
*
34-
* @return string
34+
* {@inheritDoc}
3535
*/
3636
public function getSku(): string
3737
{
3838
return $this->product->getSku();
3939
}
4040

41+
4142
/**
42-
* Returns product ID
43-
*
44-
* @return int
43+
* {@inheritDoc}
4544
*/
4645
public function getId(): int
4746
{
4847
return (int)$this->product->getId();
4948
}
5049

5150
/**
52-
* Check if product is of a type
53-
*
54-
* @param string ...$type
55-
* @return bool
51+
* {@inheritDoc}
5652
*/
5753
public function isType(string ...$type): bool
5854
{
5955
return in_array($this->product->getTypeId(), $type, true);
6056
}
6157

6258
/**
63-
* Updates field in wrapped product
64-
*
65-
* @param string $fieldName
66-
* @param $value
59+
* {@inheritDoc}
6760
*/
6861
public function updateField(string $fieldName, $value): void
6962
{

src/DataService/MagentoScopeFilter.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,33 @@
1515
class MagentoScopeFilter implements ScopeFilter
1616
{
1717
/**
18+
* Provider of the customer group
19+
*
1820
* @var CustomerGroupProvider
1921
*/
2022
private $customerGroupProvider;
23+
2124
/**
25+
* Store manager interface
26+
*
2227
* @var StoreManagerInterface
2328
*/
2429
private $storeManager;
2530

2631
/**
32+
* List of provided filter options
33+
*
2734
* @var array
2835
*/
2936
private $options;
3037

38+
/**
39+
* MagentoScopeFilter constructor.
40+
*
41+
* @param CustomerGroupProvider $customerGroupProvider
42+
* @param StoreManagerInterface $storeManager
43+
* @param array $options
44+
*/
3145
public function __construct(
3246
CustomerGroupProvider $customerGroupProvider,
3347
StoreManagerInterface $storeManager,
@@ -39,10 +53,9 @@ public function __construct(
3953
$this->options = $options;
4054
}
4155

56+
4257
/**
43-
* Scope of the filtered data to be loaded
44-
*
45-
* @return int
58+
* {@inheritDoc}
4659
*/
4760
public function getWebsiteId(): int
4861
{
@@ -51,43 +64,31 @@ public function getWebsiteId(): int
5164
}
5265

5366
/**
54-
* Store ID scope of data to be loaded
55-
*
56-
* @return int
67+
* {@inheritDoc}
5768
*/
5869
public function getStoreId(): int
5970
{
6071
return (int)$this->options['store_id'];
6172
}
6273

6374
/**
64-
* Returns true if customer group has been explicitly set
65-
*
66-
* @return bool
75+
* {@inheritDoc}
6776
*/
6877
public function hasCustomerGroupId(): bool
6978
{
7079
return isset($this->options['group_id']);
7180
}
7281

7382
/**
74-
* Returns currently applied customer group
75-
*
76-
* Call this method only if your functionality relies on a customer group to provide functionality
77-
*
78-
* Otherwise check for hasCustomerGroup() call to make sure you only filter if customer group filter is set
79-
*
80-
* @return int
83+
* {@inheritDoc}
8184
*/
8285
public function getCustomerGroupId(): int
8386
{
8487
return (int)($this->options['group_id'] ?? $this->customerGroupProvider->getCustomerGroupId());
8588
}
8689

8790
/**
88-
* Returns a cache for grouping data loaders together
89-
*
90-
* @return string
91+
* {@inheritDoc}
9192
*/
9293
public function getCacheKey(): string
9394
{

src/DataService/ProductWrapper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ public function getId(): int;
3232
* Check if product is of a type
3333
*
3434
* @param string ...$type
35+
*
3536
* @return bool
3637
*/
3738
public function isType(string ...$type): bool;
3839

3940
/**
40-
* Updates field in wrapped product
41+
* Updates field in a wrapped product
4142
*
4243
* @param string $fieldName
43-
* @param $value
44+
* @param mixed $value
45+
*
46+
* @return void
4447
*/
4548
public function updateField(string $fieldName, $value): void;
4649
}

src/DataService/ScopeFilterFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Scope filter factory
16-
*
1716
*/
1817
class ScopeFilterFactory
1918
{
@@ -38,6 +37,7 @@ public function __construct(ObjectManagerInterface $objectManager)
3837
* Create scope filter from shopping cart
3938
*
4039
* @param CartInterface $cart
40+
*
4141
* @return MagentoScopeFilter
4242
*/
4343
public function createFromCart(CartInterface $cart): MagentoScopeFilter
@@ -54,6 +54,7 @@ public function createFromCart(CartInterface $cart): MagentoScopeFilter
5454
* Create scope filter from store identifier
5555
*
5656
* @param int $storeId
57+
*
5758
* @return MagentoScopeFilter
5859
*/
5960
public function createFromStore(int $storeId): MagentoScopeFilter
@@ -70,6 +71,7 @@ public function createFromStore(int $storeId): MagentoScopeFilter
7071
*
7172
* @param int $storeId
7273
* @param ProductLimitation $productLimitation
74+
*
7375
* @return MagentoScopeFilter
7476
*/
7577
public function createFromLimitation(int $storeId, ProductLimitation $productLimitation): MagentoScopeFilter

src/Observer/CartCollectionAfterLoad.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function setCart(CartInterface $cart)
6969
*/
7070
public function execute(Observer $observer)
7171
{
72-
/** @var Collection $collection */
72+
/* @var Collection $collection */
7373
$collection = $observer->getData('collection');
7474

7575
if (!$collection instanceof Collection) {

0 commit comments

Comments
 (0)