Completed
Push — master ( 1bb428...fe8713 )
by Tobias
8s
created

Main   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 60
rs 10
c 2
b 0
f 1
wmc 5
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A connection() 0 7 2
A user() 0 4 1
A group() 0 4 1
1
<?php
2
/**
3
FreeIPA library for PHP
4
Copyright (C) 2015  Tobias Sette <[email protected]>
5
6
This program is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
// Dependencies:
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
//require_once('Connection.php');
22
//require_once('User.php');
23
//require_once('Group.php');
24
25
/**
26
 * Classes for access to FreeIPA API
27
 * @since 0.1
28
 */
29
namespace FreeIPA\APIAccess;
30
31
/**
32
 * Façade class to access all implemented methods and resources on this lib
33
 *
34
 * @author Tobias Sette <[email protected]>
35
 * @copyright Copyright (c) 2015 Tobias Sette <[email protected]>
36
 * @license LGPLv3
37
 * @package php-freeipa
38
 * @since GIT 0.1.0
39
 * @version GIT: 0.2.0
40
 */
41
class Main
42
{
43
    /**
44
     *
45
     * @var \FreeIPA\APIAccess\Connection
46
     */
47
    protected $_connection = null;
48
    
49
    /**
50
     *
51
     * @var \FreeIPA\APIAccess\User
52
     */
53
    protected $_user = null;
54
    
55
    /**
56
     *
57
     * @var \FreeIPA\APIAccess\Group
58
     */
59
    protected $_group = null;
60
61
    
62
    public function __construct($server = null, $certificate = null)
63
    {
64
        $this->_connection = $this->connection($server, $certificate);
65
        $this->_user = new \FreeIPA\APIAccess\User($this->_connection);
66
        $this->_group = $this->_group = new \FreeIPA\APIAccess\Group($this->_connection);
67
    }
68
    
69
    /**
70
     * 
71
     * @param string $server
72
     * @param string $certificate
73
     * @return \FreeIPA\APIAccess\Connection
74
     */
75
    public function connection($server = null, $certificate = null)
76
    {
77
        if (! $this->_connection) {
78
            $this->_connection = \FreeIPA\APIAccess\Connection::getInstance($server, $certificate);
0 ignored issues
show
Bug introduced by
It seems like $server defined by parameter $server on line 75 can also be of type string; however, FreeIPA\APIAccess\Connection::getInstance() does only seem to accept object<FreeIPA\APIAccess\type>|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $certificate defined by parameter $certificate on line 75 can also be of type string; however, FreeIPA\APIAccess\Connection::getInstance() does only seem to accept object<FreeIPA\APIAccess\type>|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Documentation Bug introduced by
It seems like \FreeIPA\APIAccess\Conne...($server, $certificate) can also be of type object<FreeIPA\APIAccess\instance>. However, the property $_connection is declared as type object<FreeIPA\APIAccess\Connection>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
79
        }
80
        return($this->_connection);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->_connection; of type FreeIPA\APIAccess\Connec...eIPA\APIAccess\instance adds the type FreeIPA\APIAccess\instance to the return on line 80 which is incompatible with the return type documented by FreeIPA\APIAccess\Main::connection of type FreeIPA\APIAccess\Connection.
Loading history...
81
    }
82
83
    /**
84
     * 
85
     * @return \FreeIPA\APIAccess\User
86
     */
87
    public function user()
88
    {
89
        return($this->_user);
90
    }
91
92
    /**
93
     * 
94
     * @return \FreeIPA\APIAccess\Group
95
     */
96
    public function group()
97
    {
98
        return($this->_group);
99
    }
100
}
101