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

PortfolioItemScored   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 27 2
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
8
9
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity;
10
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User;
11
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Scored;
12
use Xabbuh\XApi\Model\Result;
13
use Xabbuh\XApi\Model\Score;
14
use Xabbuh\XApi\Model\Statement;
15
16
class PortfolioItemScored extends PortfolioItem
17
{
18
    use PortfolioAttachmentsTrait;
0 ignored issues
show
Bug introduced by
The trait Chamilo\PluginBundle\XAp...rtfolioAttachmentsTrait requires the property $comment which is not provided by Chamilo\PluginBundle\XAp...ent\PortfolioItemScored.
Loading history...
19
20
    public function generate(): Statement
21
    {
22
        $user = api_get_user_entity(api_get_user_id());
23
24
        $maxScore = (float) api_get_course_setting('portfolio_max_score');
25
        $rawScore = $this->item->getScore();
26
        $scaled = $maxScore ? ($rawScore / $maxScore) : 0;
27
28
        $actor = new User($user);
29
        $verb = new Scored();
30
        $object = new PortfolioItemActivity($this->item);
31
        $context = $this->generateContext();
32
        $attachments = $this->generateAttachmentsForItem($this->item);
33
        $score = new Score($scaled, $rawScore, 0, $maxScore);
34
        $result = new Result($score);
35
36
        return new Statement(
37
            $this->generateStatementId('portfolio-item'),
38
            $actor->generate(),
39
            $verb->generate(),
40
            $object->generate(),
41
            $result,
42
            null,
43
            api_get_utc_datetime(null, false, true),
44
            null,
45
            $context,
46
            $attachments
47
        );
48
    }
49
}
50