lib/Ajde/Publisher/Twitter/Twitter.php

Summary

Maintainability
A
25 mins
Test Coverage

Function publish has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function publish()
    {
        $tweet = $this->getTitle();
        if ($url = $this->getUrl()) {
            $tweet = substr($tweet, 0, 140 - strlen($url) - 5).'... '.$url;
Severity: Minor
Found in lib/Ajde/Publisher/Twitter/Twitter.php - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

        $this->_twitter = new Ajde_Social_Provider_Twitter($this->_consumerKey, $this->_consumerSecret, $this->_token,

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

Avoid assigning values to variables in if clauses and the like (line '26', column '13').
Open

    public function publish()
    {
        $tweet = $this->getTitle();
        if ($url = $this->getUrl()) {
            $tweet = substr($tweet, 0, 140 - strlen($url) - 5).'... '.$url;

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

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

        } else {
            return false;
        }

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

Avoid using static access to class 'Ajde_Exception_Log' in method 'publish'.
Open

            Ajde_Exception_Log::logException($e);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid using static access to class 'Ajde_Log' in method 'publish'.
Open

            Ajde_Log::log($response);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid unused local variables such as '$curlength'.
Open

        while ($curlength = iconv_strlen(htmlspecialchars($tweet, ENT_QUOTES, 'UTF-8'), 'UTF-8') >= 140) {

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

The property $_token is not named in camelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_twitter is not named in camelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_tokenSecret is not named in camelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_consumerSecret is not named in camelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_consumerKey is not named in camelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The class Ajde_Publisher_Twitter is not named in CamelCase.
Open

class Ajde_Publisher_Twitter extends Ajde_Publisher
{
    private $_consumerKey;
    private $_consumerSecret;
    private $_token;

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

There are no issues that match your filters.

Category
Status