rhosocial/yii2-base-models

View on GitHub

Showing 293 of 293 total issues

The property $_access is not named in camelCase.
Open

class User extends \yii\web\User
{
    private $_access = [];

    /**
Severity: Minor
Found in web/User.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

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 18 and the first side effect is on line 18.
Open

<?php
Severity: Minor
Found in traits/config/IPConfig.php by phpcodesniffer

Function onUpdateChildren has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function onUpdateChildren($event): bool
    {
        $sender = $event->sender;
        /* @var $sender static */
        if (empty($sender->parentAttribute) || !is_string($sender->parentAttribute)) {
Severity: Minor
Found in traits/SelfBlameableTrait.php - About 45 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

Function buildRelation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    protected static function buildRelation($user, $other)
    {
        $relationQuery = static::find()->initiators($user)->recipients($other);
        $noInit = $relationQuery->noInitModel;
        $relation = $relationQuery->one();
Severity: Minor
Found in traits/UserRelationTrait.php - About 45 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

Function enabledFields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function enabledFields(): array
    {
        $fields = parent::enabledFields();
        if (is_string($this->createdByAttribute) && !empty($this->createdByAttribute)) {
            $fields[] = $this->createdByAttribute;
Severity: Minor
Found in traits/BlameableTrait.php - About 45 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

Function deleteChildren has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function deleteChildren()
    {
        $children = $this->children;
        if (empty($children)) {
            return true;
Severity: Minor
Found in traits/SelfBlameableTrait.php - About 45 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

Function onDeleteChildren has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function onDeleteChildren($event): bool
    {
        $sender = $event->sender;
        /* @var $sender static */
        if (empty($sender->parentAttribute) || !is_string($sender->parentAttribute)) {
Severity: Minor
Found in traits/SelfBlameableTrait.php - About 45 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getAuthKeyRules(): array
    {
        if (!is_string($this->authKeyAttribute) || empty($this->authKeyAttribute)) {
            return [];
        }
Severity: Minor
Found in traits/IdentityTrait.php and 1 other location - About 40 mins to fix
traits/IdentityTrait.php on lines 174..186

Duplicated Code

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).

Tuning

This issue has a mass of 93.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function getAccessTokenRules(): array
    {
        if (!is_string($this->accessTokenAttribute) || empty($this->accessTokenAttribute)) {
            return [];
        }
Severity: Minor
Found in traits/IdentityTrait.php and 1 other location - About 40 mins to fix
traits/IdentityTrait.php on lines 111..123

Duplicated Code

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).

Tuning

This issue has a mass of 93.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function insertRelation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function insertRelation($relation, ?Connection $connection = null): bool
    {
        if (!($relation instanceof static)) {
            return false;
        }
Severity: Minor
Found in traits/UserRelationTrait.php - About 35 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

There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
Open

    ){}

Scope keyword "static" must be followed by a single space
Open

    public function updatedAtToday(): static
Severity: Minor
Found in traits/EntityQueryTrait.php by phpcodesniffer

Function setIPAddress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function setIPAddress(?string $ipAddress): int|string|null
    {
        if (!$ipAddress || !$this->enableIP) {
            return null;
        }
Severity: Minor
Found in traits/IPTrait.php - About 35 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

Multi-line function declaration not indented correctly; expected 8 spaces but found 0
Open

         */

Multi-line function declaration not indented correctly; expected 8 spaces but found 0
Open

         * If not set, this function will not be enabled.

The closing brace for the class must go on the next line after the body
Open

}
Severity: Minor
Found in models/BaseMetaModel.php by phpcodesniffer

Scope keyword "static" must be followed by a single space
Open

    public function orderByCreatedAt(int|string $sort = SORT_ASC): static
Severity: Minor
Found in traits/EntityQueryTrait.php by phpcodesniffer

Scope keyword "static" must be followed by a single space
Open

    public function page(int|string|null $pageSize = 10, ?int $currentPage = 0): static
Severity: Minor
Found in traits/EntityQueryTrait.php by phpcodesniffer

Scope keyword "static" must be followed by a single space
Open

    public static function findIdentity(mixed $identity): ?static
Severity: Minor
Found in traits/IdentityTrait.php by phpcodesniffer

Property name "$_sourceRules" should not be prefixed with an underscore to indicate visibility
Open

    private array $_sourceRules = [];
Severity: Minor
Found in traits/RegistrationTrait.php by phpcodesniffer
Severity
Category
Status
Source
Language