The class UserRepository has an overall complexity of 54 which is very high. The configured complexity threshold is 50. Open
final class UserRepository implements UserRepositoryInterface
{
/**
* This returns a built user from a rsstoken
*/
- Exclude checks
The class UserRepository has 16 public methods. Consider refactoring UserRepository to keep number of public methods under 10. Open
final class UserRepository implements UserRepositoryInterface
{
/**
* This returns a built user from a rsstoken
*/
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
UserRepository
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
final class UserRepository implements UserRepositoryInterface
{
/**
* This returns a built user from a rsstoken
*/
Function findByApiKey
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function findByApiKey(string $apikey): ?User
{
if (!empty($apikey)) {
// check for legacy unencrypted apikey
$sql = "SELECT `id` FROM `user` WHERE `apikey` = ?";
- Read upRead up
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 findByStreamToken
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function findByStreamToken(string $streamToken): ?User
{
if (!empty($streamToken)) {
// check for legacy unencrypted streamtoken
$sql = "SELECT `id` FROM `user` WHERE `streamtoken` = ?";
- Read upRead up
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
Avoid assigning values to variables in if clauses and the like (line '236', column '13'). Open
public function findByUsername(string $username): ?User
{
$user = null;
$sql = 'SELECT `id` FROM `user` WHERE `username` = ?';
$db_results = Dba::read($sql, array($username));
- Read upRead up
- Exclude checks
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
Avoid assigning values to variables in if clauses and the like (line '42', column '13'). Open
public function getByRssToken(string $rssToken): ?User
{
$user = null;
$sql = "SELECT `id` FROM `user` WHERE `rsstoken` = ?";
$db_results = Dba::read($sql, array($rssToken));
- Read upRead up
- Exclude checks
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
Avoid assigning values to variables in if clauses and the like (line '251', column '13'). Open
public function findByEmail(string $email): ?User
{
$user = null;
$sql = 'SELECT `id` FROM `user` WHERE `email` = ?';
$db_results = Dba::read($sql, array($email));
- Read upRead up
- Exclude checks
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
Avoid unused parameters such as '$userName'. Open
public function updateStreamToken(int $userId, string $userName, string $streamToken): void
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
syntax error, unexpected end of file
Open
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
while ($row = Dba::fetch_assoc($db_results)) {
if ($row['streamtoken'] && $row['username']) {
$key = hash('sha256', $row['streamtoken']);
$passphrase = hash('sha256', $row['username'] . $key);
if ($passphrase == $streamToken) {
- Read upRead up
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 103.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
while ($row = Dba::fetch_assoc($db_results)) {
if ($row['apikey'] && $row['username']) {
$key = hash('sha256', $row['apikey']);
$passphrase = hash('sha256', $row['username'] . $key);
if ($passphrase == $apikey) {
- Read upRead up
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 103.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function getByRssToken(string $rssToken): ?User
{
$user = null;
$sql = "SELECT `id` FROM `user` WHERE `rsstoken` = ?";
$db_results = Dba::read($sql, array($rssToken));
- Read upRead up
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 90.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function findByUsername(string $username): ?User
{
$user = null;
$sql = 'SELECT `id` FROM `user` WHERE `username` = ?';
$db_results = Dba::read($sql, array($username));
- Read upRead up
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 90.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function findByEmail(string $email): ?User
{
$user = null;
$sql = 'SELECT `id` FROM `user` WHERE `email` = ?';
$db_results = Dba::read($sql, array($email));
- Read upRead up
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 90.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 37 and the first side effect is on line 32. Open
<?php
- Exclude checks
Possible parse error: class missing opening or closing brace Open
final class UserRepository implements UserRepositoryInterface
- Exclude checks
Possible parse error: class missing opening or closing brace Open
final class UserRepository implements UserRepositoryInterface
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
foreach ($user_tables as $table_id) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function idByResetToken(string $token): int
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function findByUsername(string $username): ?User
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getByRssToken(string $rssToken): ?User
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($result !== null) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getValid(bool $includeDisabled = false): array
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function findByEmail(string $email): ?User
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function idByEmail(string $email): int
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if (User::is_cached($key, $value)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($username == '-1') {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
foreach ($user_tables as $table_id) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if (User::is_cached($key, $value)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function idByUsername(string $username): int
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function collectGarbage(): void
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
if ($token === $user_token) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if ($result !== null) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getValidArray(bool $includeDisabled = false): array
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function findByWebsite(string $website): array
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getValidationByUsername(string $username): ?string
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
if (array_key_exists('id', $results)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function enable(int $userId): void
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
if ($row['streamtoken'] && $row['username']) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function updateLastSeen(
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
if ($passphrase == $streamToken) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
if ($passphrase == $apikey) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function updateStreamToken(int $userId, string $userName, string $streamToken): void
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if (!empty($apikey)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function updateRssToken(int $userId, string $rssToken): void
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
if (array_key_exists('username', $results)) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if (!empty($streamToken)) {
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function activateByUsername(string $username): void
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function updateApiKey(int $userId, string $apikey): void
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function findByStreamToken(string $streamToken): ?User
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
if ($row['apikey'] && $row['username']) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getStatistics(int $timePeriod = 1200): array
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function findByApiKey(string $apikey): ?User
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
if (array_key_exists('id', $results)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function retrievePasswordFromUser(int $userId): string
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks