GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 32bit-pull ( 17748e )
by
unknown
16:44 queued 06:09
created

TypeHelperTrait::checkType()   C

Complexity

Conditions 11
Paths 16

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 33
rs 5.2653
cc 11
eloc 19
nc 16
nop 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Dkd\PhpCmis\Traits;
3
4
/**
5
 * This file is part of php-cmis-lib.
6
 *
7
 * (c) Sascha Egerer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException;
14
15
/**
16
 * Trait with some type check related functions
17
 */
18
trait TypeHelperTrait
19
{
20
    /**
21
     * Check if the given value is the expected object type
22
     *
23
     * @param string $expectedType the expected object type (class name)
24
     * @param mixed $value The value that has to be checked
25
     * @param boolean $nullAllowed Is <code>null</code> allowed as value?
26
     * @return boolean returns <code>true</code> if the given value is instance of expected type
27
     * @throws CmisInvalidArgumentException Exception is thrown if the given value does not match to the expected type
28
     */
29
    protected function checkType($expectedType, $value, $nullAllowed = false)
30
    {
31
        $invalidType = null;
32
        $valueType = gettype($value);
33
        $nullAllowed = (boolean) $nullAllowed;
34
35
        if ($valueType === 'object') {
36
            if (!is_a($value, $expectedType)) {
37
                $invalidType = get_class($value);
38
            }
39
        } elseif ($expectedType !== $valueType) {
40
            $invalidType = $valueType;
41
        }
42
43
        if (PHP_INT_SIZE == 4 && $invalidType == "double" && $expectedType == "integer")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal double does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal integer does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
44
        {
45
            //TODO: 32bit - handle this specially?
46
            $invalidType = null;
47
        }
48
49
        if ($invalidType !== null && ($nullAllowed === false || ($nullAllowed === true && $value !== null))) {
50
            throw new CmisInvalidArgumentException(
51
                sprintf(
52
                    'Argument of type "%s" given but argument of type "%s" was expected.',
53
                    $invalidType,
54
                    $expectedType
55
                ),
56
                1413440336
57
            );
58
        }
59
60
        return true;
61
    }
62
63
    /**
64
     * Ensure that a value is an instance of the expected type. If not the value
65
     * is casted to the expected type and a log message is triggered.
66
     *
67
     * @param string $expectedType the expected object type (class name)
68
     * @param mixed $value The value that has to be checked
69
     * @param boolean $nullIsValidValue defines if <code>null</code> is also a valid value
70
     * @return mixed
71
     */
72
    protected function castValueToSimpleType($expectedType, $value, $nullIsValidValue = false)
73
    {
74
        try {
75
            $this->checkType($expectedType, $value, $nullIsValidValue);
76
        } catch (CmisInvalidArgumentException $exception) {
77
            if (PHP_INT_SIZE == 4 && $expectedType == "integer" && gettype($value) == "double") {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
Coding Style Comprehensibility introduced by
The string literal integer does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal double does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
78
                //TODO: 32bit - handle this specially?
79
            } else {
80
                trigger_error(
81
                    sprintf(
82
                        'Given value is of type "%s" but a value of type "%s" was expected.'
83
                        . ' Value has been casted to the expected type.',
84
                        gettype($value),
85
                        $expectedType
86
                    ),
87
                    E_USER_NOTICE
88
                );
89
                settype($value, $expectedType);
90
            }
91
        }
92
93
        return $value;
94
    }
95
}
96