bwinkers/nugget

View on GitHub
src/bin/readPropertiesFromGoogle.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid using undefined variables such as '$resolved' which will lead to PHP notices.
Open

    $property = array_merge($property, $resolved);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$resolved' which will lead to PHP notices.
Open

    $resolved['oneOf'] = $resolvedTypes;
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Missing class import via use statement (line '150', column '19').
Open

    $nugget = new \Activerules\Nugget\Nugget();
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

The method hydrateTypes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

    } else {
        hydrateOneOfType($property, $types);
    }
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

The method resolveType uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

    } else {
        // Assume we got a valid Schema name
        $resolved['$ref'] = "#/components/schema/" . $type;
    }
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Define a constant instead of duplicating this literal "types" 3 times.
Open

        $property['types'] = explode(' or ', $propertyRow[1]);
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Suspicious attempt to unset an offset of a value of type string
Open

    unset($property['types']);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Variable $resolved was undeclared, but array fields are being added to it.
Open

    $resolved['oneOf'] = $resolvedTypes;
Severity: Info
Found in src/bin/readPropertiesFromGoogle.php by phan

Returning type array{$ref:string}|array{type:,nuggetType:string} but resolveType() is declared to return string
Open

    return $resolved;
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Suspicious array access to \type
Open

    return file_exists(PROPERTYDIR + DIRECTORY_SEPARATOR + $property['name'] + '.json');
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Call to method __construct from undeclared class \Google_Client
Open

$client = new Google_Client();
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Reference to instance property spreadsheets_values from undeclared class \Google_Service_Sheets
Open

$response = $service->spreadsheets_values->get($spreadsheetID, $range);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Parameter $properties has undeclared type \type
Open

function processProperties($properties)
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Return type of propertyExists() is undeclared type \type
Open

function propertyExists($property)
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (filename) is float|int but \file_exists() takes string
Open

    return file_exists(PROPERTYDIR + DIRECTORY_SEPARATOR + $property['name'] + '.json');
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (property) is string but \propertyExists() takes \type defined at /code/src/bin/readPropertiesFromGoogle.php:192
Open

    if (propertyExists($property)) {
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

When fetching an array index from a value of type string, found an array index of type 'types', but expected the index to be of type int
Open

    $types = $property['types'];
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (arr1) is string but \array_merge() takes array
Open

    $property = array_merge($property, $resolved);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Parameter $property has undeclared type \type
Open

function propertyExists($property)
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Reference to constant SPREADSHEETS_READONLY from undeclared class \Google_Service_Sheets
Open

define('SCOPES', implode(' ', array(Google_Service_Sheets::SPREADSHEETS_READONLY)));
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (property) is array{description:mixed,types:array<int>,name:mixed}</int> but \processProperty() takes string defined at /code/src/bin/readPropertiesFromGoogle.php:71
Open

        processProperty($property);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

When fetching an array index from a value of type string, found an array index of type 'name', but expected the index to be of type int
Open

    $propertyName = $property['name'];
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Returning type bool but propertyExists() is declared to return \type
Open

    return file_exists(PROPERTYDIR + DIRECTORY_SEPARATOR + $property['name'] + '.json');
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Call to method setScopes from undeclared class \Google_Client
Open

$client->setScopes(SCOPES);
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Call to method __construct from undeclared class \Google_Service_Sheets
Open

$service = new Google_Service_Sheets($client);
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Method \processProperty is declared to return string but has no return value
Open

function processProperty($property)
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Call to undeclared method \Activerules\Nugget\Nugget::jsonType
Open

    $jsonType = $nugget->jsonType($type);
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (arr1) is string but \array_merge() takes array
Open

    $property = array_merge($property, $typeData);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 1 (var) is string but \count() takes \Countable|array
Open

    if (count($types) === 1) {
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Call to method useApplicationDefaultCredentials from undeclared class \Google_Client
Open

$client->useApplicationDefaultCredentials();
Severity: Critical
Found in src/bin/readPropertiesFromGoogle.php by phan

Suspicious attempt to unset an offset of a value of type string
Open

    unset($property['name']);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Returning type void but processProperty() is declared to return string
Open

        return;
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 2 (types) is string but \hydrateOneOfType() takes array defined at /code/src/bin/readPropertiesFromGoogle.php:117
Open

        hydrateOneOfType($property, $types);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

Argument 2 (args) is string but \array_merge() takes array
Open

    $property = array_merge($property, $typeData);
Severity: Minor
Found in src/bin/readPropertiesFromGoogle.php by phan

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 19 and the first side effect is on line 3.
Open

<?php

There are no issues that match your filters.

Category
Status