Passed
Push — master ( 95b92f...37aede )
by Yannick
10:09 queued 01:17
created

PortfolioItem   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generate() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity;
8
9
use Chamilo\CoreBundle\Entity\Portfolio;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Chamilo\PluginBundle\XAp...ence\Activity\Portfolio. 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...
10
use Xabbuh\XApi\Model\Activity;
11
use Xabbuh\XApi\Model\Definition;
12
use Xabbuh\XApi\Model\IRI;
13
use Xabbuh\XApi\Model\LanguageMap;
14
15
/**
16
 * Class PortfolioItem.
17
 */
18
class PortfolioItem extends BaseActivity
19
{
20
    /**
21
     * @var Portfolio
22
     */
23
    private $item;
24
25
    public function __construct(Portfolio $item)
26
    {
27
        $this->item = $item;
28
    }
29
30
    public function generate(): Activity
31
    {
32
        $langIso = api_get_language_isocode();
33
34
        $iri = $this->generateIri(
35
            WEB_CODE_PATH,
36
            'portfolio/index.php',
37
            ['action' => 'view', 'id' => $this->item->getId()]
38
        );
39
40
        return new Activity(
41
            IRI::fromString($iri),
42
            new Definition(
43
                LanguageMap::create([$langIso => $this->item->getTitle()]),
44
                null,
45
                IRI::fromString('http://activitystrea.ms/schema/1.0/article')
46
            )
47
        );
48
    }
49
}
50