railpage/railpagecore

View on GitHub
lib/Newsletters/Newsletters.php

Summary

Maintainability
B
4 hrs
Test Coverage

The method getTemplate has a boolean flag argument $id, which is a certain sign of a Single Responsibility Principle violation.
Open

        public function getTemplate($id = false) {
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

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

        public function subscribeUser(User $User, $newsletter) {
            
            $this->changeSubscription($User, $newsletter, 1); 
            
            return $this;
Severity: Major
Found in lib/Newsletters/Newsletters.php and 1 other location - About 1 hr to fix
lib/Newsletters/Newsletters.php on lines 117..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 33.

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 unSubscribeUser(User $User, $newsletter) {
            
            $this->changeSubscription($User, $newsletter, 0); 
            
            return $this;
Severity: Major
Found in lib/Newsletters/Newsletters.php and 1 other location - About 1 hr to fix
lib/Newsletters/Newsletters.php on lines 101..107

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

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 25 locations. Consider refactoring.
Open

            if (!filter_var($User->id, FILTER_VALIDATE_INT)) {
                throw new InvalidArgumentException("The provided user is invalid - no user ID"); 
            }
Severity: Major
Found in lib/Newsletters/Newsletters.php and 24 other locations - About 1 hr to fix
lib/Downloads/Download.php on lines 313..315
lib/Events/Event.php on lines 425..427
lib/Events/Events.php on lines 130..132
lib/Images/Competition.php on lines 624..626
lib/Images/Competition.php on lines 654..656
lib/Images/Competition.php on lines 823..825
lib/Images/Competition.php on lines 860..862
lib/Images/Favourites.php on lines 112..114
lib/Images/Favourites.php on lines 178..180
lib/Jobs/Classification.php on lines 80..82
lib/Locations/Location.php on lines 406..408
lib/Locations/Location.php on lines 410..412
lib/Locos/Locomotive.php on lines 622..624
lib/Locos/Locomotive.php on lines 626..628
lib/Locos/Locomotive.php on lines 897..899
lib/News/Article.php on lines 361..363
lib/News/Article.php on lines 834..836
lib/PrivateMessages/Message.php on lines 244..246
lib/PrivateMessages/Message.php on lines 452..454
lib/Railcams/Photo.php on lines 330..332
lib/Railcams/Storage.php on lines 224..226
lib/Sightings/Sighting.php on lines 133..135
lib/Users/Group.php on lines 236..238
lib/Warnings/Warning.php on lines 209..211

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

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 5 locations. Consider refactoring.
Open

            foreach ($this->db->fetchAll("SELECT * FROM newsletter") as $row) {
                $Newsletter = new Newsletter($row['id']); 
                $return[] = $Newsletter->getArray(); 
            }
Severity: Major
Found in lib/Newsletters/Newsletters.php and 4 other locations - About 1 hr to fix
lib/Images/Competitions.php on lines 123..126
lib/Locos/Manufacturer.php on lines 192..196
lib/Locos/Type.php on lines 191..195
lib/Sightings/Sightings.php on lines 119..122

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

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

            $query = "INSERT INTO nuke_users_flags (user_id, " . $column . ") VALUES(" . $User->id . ", " . $value . ") ON DUPLICATE KEY UPDATE " . $column . " = VALUES(" . $column . ")";
Severity: Minor
Found in lib/Newsletters/Newsletters.php and 1 other location - About 30 mins to fix
lib/Forums/Post.php on lines 557..557

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

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

The parameter $User is not named in camelCase.
Open

        public static function getSubscriptionFlags(User $User) {
            
            $Database = AppCore::GetDatabase(); 
            
            $query = "SELECT COALESCE(newsletter_daily, 1) AS newsletter_daily,
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $User is not named in camelCase.
Open

        public function subscribeUser(User $User, $newsletter) {
            
            $this->changeSubscription($User, $newsletter, 1); 
            
            return $this;
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $User is not named in camelCase.
Open

        public function unSubscribeUser(User $User, $newsletter) {
            
            $this->changeSubscription($User, $newsletter, 0); 
            
            return $this;
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $User is not named in camelCase.
Open

        private function changeSubscription(User $User, $newsletter, $value) {
            
            if (!filter_var($User->id, FILTER_VALIDATE_INT)) {
                throw new InvalidArgumentException("The provided user is invalid - no user ID"); 
            }
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $User is not named in camelCase.
Open

        public static function lastWeeklyDispatchDate(User $User) {
            
            $query = "SELECT newsletter_weekly_last FROM nuke_users_flags WHERE user_id = ?";
            
            $date = AppCore::getDatabase()->fetchOne($query, $User->id); 
Severity: Minor
Found in lib/Newsletters/Newsletters.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

        }

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

        }

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

        }

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

        }

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function subscribeUser(User $User, $newsletter) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!filter_var($id, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        private function changeSubscription(User $User, $newsletter, $value) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            foreach ($this->db->fetchAll("SELECT * FROM newsletter") as $row) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function getTemplates() {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!filter_var($User->id, FILTER_VALIDATE_INT)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public static function getSubscriptionFlags(User $User) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function getTemplate($id = false) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 0 spaces, found 4
Open

    class Newsletters extends AppCore {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public static function lastWeeklyDispatchDate(User $User) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function unSubscribeUser(User $User, $newsletter) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            if ($date) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (strpos($newsletter, "newsletter_") === false) {

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

Line indented incorrectly; expected 8 spaces, found 12
Open

            if (!$r->getConstant($newsletter)) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        public function getNewsletters() {

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 8 spaces, found 12
Open

            }

There are no issues that match your filters.

Category
Status