Showing 55 of 55 total issues
Function fuzzy_ago
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
public function fuzzy_ago( $seconds, $dictionary = 'english' ) {
if ( $seconds < 0 ) {
return false;
}
- 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 Filter
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public static function Filter( $haystack, $needle, $key = false, $options = [] ) {
// Set the defaults if not already set
$max = ( isset( $options['max_results'] ) ) ? $options['max_results'] : false;
$fold_diacritics = ( isset( $options['fold'] ) ) ? $options['fold'] : true;
$match_type = ( isset( $options['match_type'] ) ) ? $options['match_type'] : MATCH_ALL;
- 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
Method convert_number_to_words
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function convert_number_to_words( $number, $dictionary = 'english' ) {
// This is a complex function, but I'm not sure if it can be simplified.
// adapted from http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
$hyphen = '-';
$conjunction = ' and ';
Function create_request
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
private function create_request( $url, $options, $cache_ttl, $cache_bin, $type ) {
if ( $cache_ttl > 0 ) {
// Create an object with caching on
$request = new Alphred\Request( $url, [ 'cache' => true,
- 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
Method fuzzy_ago
has 93 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function fuzzy_ago( $seconds, $dictionary = 'english' ) {
if ( $seconds < 0 ) {
return false;
}
Alphred
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class Alphred {
/**
* Initializes the wrapper object
*
Function execute
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function execute( $code = false ) {
// Set a preliminary HTTP response code of 0 (not defined)
$this->code = 0;
- 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 filter_item
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private static function filter_item( $value, $query, $match_on, $fold_diacritics ) {
$query = strtolower( $query );
if ( $fold_diacritics ) {
$value = self::convert( $value );
- 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
Request
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class Request {
/**
* The internal cURL handler
* @var Resource
Method filter_item
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function filter_item( $value, $query, $match_on, $fold_diacritics ) {
$query = strtolower( $query );
if ( $fold_diacritics ) {
$value = self::convert( $value );
Function write_item
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
private function write_item( $item ) {
// The information we need is stored in the sub variable, so let's just get that
$item = $item->data;
// These go in the 'item' part as an attribute
$attributes = [ 'uid', 'arg', 'autocomplete' ];
- 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
File Date.php
has 272 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Contains Date class for Alphred
*
* PHP version 5
Function create
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function create( $start, $options, $selections ) {
// The beginning of the script
$script = "osascript -e '{$start}";
- 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 convert_number_to_words
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function convert_number_to_words( $number, $dictionary = 'english' ) {
// This is a complex function, but I'm not sure if it can be simplified.
// adapted from http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
$hyphen = '-';
$conjunction = ' and ';
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
<?php
/**
* Include file for when using Alphred through the cli-server SAPI
*
* If you write your workflow so that it takes advatage of the cli-server
- 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 126.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
<?php
/**
* Include file for when using Alphred through the cli-server SAPI
*
* If you write your workflow so that it takes advatage of the cli-server
- 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 126.
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
Function __call
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function __call( $called, $arguments ) {
// Make sure that the method is supposed to exist
if ( 0 !== strpos( $called, 'set_' ) ) {
// We should raise an exception here instead.
return false;
- 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
Method Filter
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function Filter( $haystack, $needle, $key = false, $options = [] ) {
// Set the defaults if not already set
$max = ( isset( $options['max_results'] ) ) ? $options['max_results'] : false;
$fold_diacritics = ( isset( $options['fold'] ) ) ? $options['fold'] : true;
$match_type = ( isset( $options['match_type'] ) ) ? $options['match_type'] : MATCH_ALL;
Method execute
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute( $code = false ) {
// Set a preliminary HTTP response code of 0 (not defined)
$this->code = 0;
Function flatten_array
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function flatten_array( $array, $prefix = '' ) {
if ( ! is_array( $array ) ) {
return $array;
}
if ( ! self::is_assoc( $array ) ) {
- 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"