morris/lessql

File is too long

<?php

namespace LessQL;

/**
Severity: Minor
Found in src/LessQL/Database.php - About 3 days to fix

File is too long

<?php

namespace LessQL;

/**
Severity: Minor
Found in src/LessQL/Result.php - About 1 day to fix

File is too long

<?php

namespace LessQL;

/**
Severity: Minor
Found in src/LessQL/Row.php - About 1 day to fix

Identical code found in 1 other location

<?php

require_once 'vendor/autoload.php';
require_once 'BaseTest.php';

Found in tests/DatabaseTest.php and 1 other location - About 1 day to fix
tests/DatabaseTest.php on lines 153..188

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Identical code found in 1 other location

<?php

require_once 'vendor/autoload.php';
require_once 'BaseTest.php';

Found in tests/DatabaseTest.php and 1 other location - About 1 day to fix
tests/DatabaseTest.php on lines 192..227

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

High overall complexity: 107

<?php

namespace LessQL;

/**
Found in src/LessQL/Database.php - About 1 day to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Class Database contains too many public methods

class Database {

    /**
     * Constructor. Sets PDO to exception mode.
     *
Severity: Minor
Found in src/LessQL/Database.php - About 3 hrs to fix

Complex method in is

    function is( $column, $value, $not = false ) {

        $bang = $not ? "!" : "";
        $or = $not ? " AND " : " OR ";
        $novalue = $not ? "1=1" : "0=1";
Found in src/LessQL/Database.php - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in save

    function save( $recursive = true ) {

        $db = $this->getDatabase();
        $table = $this->getTable();

Found in src/LessQL/Row.php - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Class Result contains too many public methods

class Result implements \IteratorAggregate, \JsonSerializable {

    /**
     * Constructor
     * Use $db->createResult( $parent, $name ) instead
Severity: Minor
Found in src/LessQL/Result.php - About 2 hrs to fix

Class Row contains too many public methods

class Row implements \ArrayAccess, \IteratorAggregate, \JsonSerializable {

    /**
     * Constructor
     * Use $db->createRow() instead
Severity: Minor
Found in src/LessQL/Row.php - About 2 hrs to fix

File is too long

<?php

require_once 'vendor/autoload.php';
require_once 'BaseTest.php';

Severity: Minor
Found in tests/ResultTest.php - About 2 hrs to fix

Complex method in execute

    function execute() {

        if ( isset( $this->rows ) ) return $this;

        if ( $this->parent_ ) {
Found in src/LessQL/Result.php - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Method save is too long

    function save( $recursive = true ) {

        $db = $this->getDatabase();
        $table = $this->getTable();

Severity: Minor
Found in src/LessQL/Row.php - About 2 hrs to fix

Complex method in testTraversal

    function testTraversal() {

        $db = self::$db;

        $posts = array();
Found in tests/ResultTest.php - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in __construct

    function __construct( $parent, $name ) {

        if ( $parent instanceof Database ) {

            // basic result
Found in src/LessQL/Result.php - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Method reset is too long

    static function reset() {

        self::$pdo->beginTransaction();

        // sequences
Severity: Minor
Found in tests/BaseTest.php - About 1 hr to fix

Method schema is too long

    static function schema() {

        self::$pdo->beginTransaction();

        //
Severity: Minor
Found in tests/BaseTest.php - About 1 hr to fix

Class ResultTest contains too many public methods

class ResultTest extends BaseTest {

    function testPrimary() {

        $db = self::$db;
Severity: Minor
Found in tests/ResultTest.php - About 1 hr to fix

Method is is too long

    function is( $column, $value, $not = false ) {

        $bang = $not ? "!" : "";
        $or = $not ? " AND " : " OR ";
        $novalue = $not ? "1=1" : "0=1";
Severity: Minor
Found in src/LessQL/Database.php - About 1 hr to fix

Method execute is too long

    function execute() {

        if ( isset( $this->rows ) ) return $this;

        if ( $this->parent_ ) {
Severity: Minor
Found in src/LessQL/Result.php - About 1 hr to fix

Cyclomatic complexity for function save is too high

    function save( $recursive = true ) {

        $db = $this->getDatabase();
        $table = $this->getTable();

Severity: Minor
Found in src/LessQL/Row.php - About 1 hr to fix

Method testTraversal is too long

    function testTraversal() {

        $db = self::$db;

        $posts = array();
Severity: Minor
Found in tests/ResultTest.php - About 1 hr to fix

Class RowTest contains too many public methods

class RowTest extends BaseTest {

    function testAccess() {

        $db = self::$db;
Severity: Minor
Found in tests/RowTest.php - About 45 mins to fix

Class DatabaseTest contains too many public methods

class DatabaseTest extends BaseTest {

    function testTable() {

        $db = self::$db;
Severity: Minor
Found in tests/DatabaseTest.php - About 30 mins to fix

The function name, is, is too short

    function is( $column, $value, $not = false ) {

        $bang = $not ? "!" : "";
        $or = $not ? " AND " : " OR ";
        $novalue = $not ? "1=1" : "0=1";
Severity: Minor
Found in src/LessQL/Database.php - About 25 mins to fix

The variable name, id, is too short

                $id = array( $primary => $id );
Severity: Minor
Found in src/LessQL/Database.php - About 5 mins to fix

The variable name, or, is too short

        $or = $not ? " AND " : " OR ";
Severity: Minor
Found in src/LessQL/Database.php - About 5 mins to fix

The variable name, or, is too short

            $or = array();
Severity: Minor
Found in src/LessQL/Result.php - About 5 mins to fix

The variable name, db, is too short

    protected $db;
Severity: Minor
Found in src/LessQL/Result.php - About 5 mins to fix

The variable name, id, is too short

            $id = array();
Severity: Minor
Found in src/LessQL/Row.php - About 5 mins to fix

The variable name, db, is too short

        $db = $this->getDatabase();
Severity: Minor
Found in src/LessQL/Row.php - About 5 mins to fix

The variable name, db, is too short

    static $db;
Severity: Minor
Found in tests/BaseTest.php - About 5 mins to fix

The variable name, p, is too short

            $p = "INTEGER PRIMARY KEY AUTOINCREMENT";
Severity: Minor
Found in tests/BaseTest.php - About 5 mins to fix

The variable name, db, is too short

        $db = self::$db;
Severity: Minor
Found in tests/DatabaseTest.php - About 5 mins to fix

The variable name, ex, is too short

        $ex = array( 'user', 'user', 'user', 'user', 1, 2 );
Severity: Minor
Found in tests/DatabaseTest.php - About 5 mins to fix

The variable name, a, is too short

        $a = array(
            $result1->getTable(),
            $result2->getTable(),
            $row1->getTable(),
            $row2->getTable(),
Severity: Minor
Found in tests/DatabaseTest.php - About 5 mins to fix

The variable name, d, is too short

        $d = $db->getIdentifierDelimiter();
Severity: Minor
Found in tests/DatabaseTest.php - About 5 mins to fix

The variable name, db, is too short

        $db = self::$db;
Severity: Minor
Found in tests/ResultTest.php - About 5 mins to fix

The variable name, a, is too short

        $a = $db->user( 2 );
Severity: Minor
Found in tests/ResultTest.php - About 5 mins to fix

The variable name, b, is too short

        $b = $db->user( 3 );
Severity: Minor
Found in tests/ResultTest.php - About 5 mins to fix

The variable name, c, is too short

        $c = $db->user( 42 );
Severity: Minor
Found in tests/ResultTest.php - About 5 mins to fix

The variable name, t, is too short

            $t = array();
Severity: Minor
Found in tests/ResultTest.php - About 5 mins to fix

The variable name, db, is too short

        $db = self::$db;
Severity: Minor
Found in tests/RowTest.php - About 5 mins to fix

The variable name, a, is too short

        $a = array(
            $row[ 'name' ],
            $row->name,
            $row[ 'id' ],
            $row->id,
Severity: Minor
Found in tests/RowTest.php - About 5 mins to fix

The variable name, ex, is too short

        $ex = array(
            'Foo Bar',
            'Foo Bar',
            null,
            null,
Severity: Minor
Found in tests/RowTest.php - About 5 mins to fix

The variable name, i, is too short

        $i = 0;
Severity: Minor
Found in tests/RowTest.php - About 5 mins to fix

Join us for Code Climate
Summit on July 19 in NYC.

Tickets on sale now.