Passed
Pull Request — master (#5629)
by Angel Fernando Quiroz
10:06 queued 01:32
created

BaseStatement::generateStatementId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
nc 1
nop 1
dl 0
loc 8
c 1
b 0
f 0
cc 1
rs 10
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\Course as CourseActivity;
10
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Site as SiteActivity;
11
use Xabbuh\XApi\Model\Context;
12
use Xabbuh\XApi\Model\ContextActivities;
13
use Xabbuh\XApi\Model\Statement;
14
use Xabbuh\XApi\Model\StatementId;
15
use Xabbuh\XApi\Model\Uuid;
16
use XApiPlugin;
17
18
/**
19
 * Class BaseStatement.
20
 */
21
abstract class BaseStatement
22
{
23
    abstract public function generate(): Statement;
24
25
    protected function generateStatementId(string $type): StatementId
26
    {
27
        $uuid = Uuid::uuid5(
28
            XApiPlugin::create()->get(XApiPlugin::SETTING_UUID_NAMESPACE),
29
            uniqid($type)
30
        );
31
32
        return StatementId::fromUuid($uuid);
33
    }
34
35
    protected function generateContext(): Context
36
    {
37
        $platform = api_get_setting('Institution').' - '.api_get_setting('siteName');
0 ignored issues
show
Bug introduced by
Are you sure api_get_setting('Institution') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $platform = /** @scrutinizer ignore-type */ api_get_setting('Institution').' - '.api_get_setting('siteName');
Loading history...
Bug introduced by
Are you sure api_get_setting('siteName') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $platform = api_get_setting('Institution').' - './** @scrutinizer ignore-type */ api_get_setting('siteName');
Loading history...
38
39
        $groupingActivities = [];
40
        $groupingActivities[] = (new SiteActivity())->generate();
41
42
        if (api_get_course_id()) {
43
            $groupingActivities[] = (new CourseActivity())->generate();
44
        }
45
46
        return (new Context())
47
            ->withPlatform($platform)
48
            ->withLanguage(api_get_language_isocode())
49
            ->withContextActivities(
50
                new ContextActivities(null, $groupingActivities)
51
            )
52
        ;
53
    }
54
}
55