ProductRelatedProductService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace Hideyo\Ecommerce\Framework\Services\Product;
4
 
5
use App\Product;
0 ignored issues
show
Bug introduced by
The type App\Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
use Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductRelatedProductRepository;
8
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Hideyo\Ecommerce\Framewo...\Product\ProductService. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use Hideyo\Ecommerce\Framework\Services\BaseService;
10
 
11
class ProductRelatedProductService extends BaseService
12
{
13
	public function __construct(ProductRelatedProductRepository $productRelated)
14
	{
15
		$this->repo = $productRelated;
0 ignored issues
show
Bug Best Practice introduced by
The property repo does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
	} 
17
18
    public function create(array $attributes, $productParentId)
19
    {
20
        $parentProduct = ProductService::find($productParentId);
21
   
22
        if (isset($attributes['products'])) {
23
            $parentProduct->relatedProducts()->attach($attributes['products']);
24
        }
25
26
        return $parentProduct->save();
27
    }
28
29
}