Passed
Pull Request — 1.11.x (#4368)
by Angel Fernando Quiroz
08:24
created

PortfolioItem   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateContext() 0 20 2
A __construct() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
6
7
use Chamilo\CoreBundle\Entity\Portfolio;
8
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
9
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioCategory;
10
use Chamilo\UserBundle\Entity\User;
11
use Xabbuh\XApi\Model\Context;
12
13
abstract class PortfolioItem extends BaseStatement
14
{
15
    protected $item;
16
17
    public function __construct(Portfolio $item)
18
    {
19
        $this->item = $item;
20
    }
21
22
    protected function generateContext(): Context
23
    {
24
        $context = parent::generateContext();
25
26
        $category = $this->item->getCategory();
27
28
        if ($category) {
0 ignored issues
show
introduced by
$category is of type Chamilo\CoreBundle\Entity\PortfolioCategory, thus it always evaluated to true.
Loading history...
29
            $categoryActivity = new PortfolioCategory($category);
30
31
            $contextActivities = $context
32
                ->getContextActivities()
33
                ->withAddedCategoryActivity(
34
                    $categoryActivity->generate()
35
                )
36
            ;
37
38
            $context  = $context->withContextActivities($contextActivities);
39
        }
40
41
        return $context;
42
    }
43
}