Organization::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organization\web\twig\variables;
10
11
use craft\elements\User;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, flipbox\organization\web\twig\variables\User.

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...
12
use flipbox\organization\elements\db\Organization as OrganizationQuery;
13
use flipbox\organization\elements\Organization as OrganizationElement;
14
use flipbox\organization\Organization as OrganizationPlugin;
15
use yii\di\ServiceLocator;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Organization extends ServiceLocator
22
{
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function __construct($config = [])
28
    {
29
30
        parent::__construct(array_merge(
31
            $config,
32
            [
33
                'components' => [
34
                    'organization' => __NAMESPACE__ . '\Organization',
35
                    'settings' => __NAMESPACE__ . '\Settings',
36
                    'type' => __NAMESPACE__ . '\Type',
37
                    'user' => __NAMESPACE__ . '\User'
38
                ]
39
            ]
40
        ));
41
    }
42
43
    /**
44
     * Configure a query.
45
     *
46
     * @param mixed $criteria
47
     * @return OrganizationQuery
48
     */
49
    public function getQuery($criteria = null)
50
    {
51
        return OrganizationPlugin::getInstance()->getOrganization()->getQuery($criteria);
52
    }
53
54
    /**
55
     * Configure a query.
56
     *
57
     * @param mixed $criteria
58
     * @return OrganizationQuery
59
     */
60
    public function find($criteria = null)
61
    {
62
        return $this->getQuery($criteria);
63
    }
64
65
    /**
66
     * @param array $config
67
     * @return \craft\base\Element|OrganizationElement
68
     */
69
    public function create(array $config = [])
70
    {
71
        return OrganizationPlugin::getInstance()->getOrganization()->create($config);
72
    }
73
74
    /**
75
     * Sub-Variables that are accessed 'craft.organization.settings'
76
     *
77
     * @return null|object|Settings
78
     */
79
    public function getSettings()
80
    {
81
        return $this->get('settings');
82
    }
83
84
    /**
85
     * Sub-Variables that are accessed 'craft.organization.type'
86
     *
87
     * @return null|object|Type
88
     */
89
    public function getType()
90
    {
91
        return $this->get('type');
92
    }
93
94
    /**
95
     * Sub-Variables that are accessed 'craft.organization.user'
96
     *
97
     * @return null|object|User
98
     */
99
    public function getUser()
100
    {
101
        return $this->get('user');
102
    }
103
}
104