Function get_channel_messages_for_datetime_range
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
function get_channel_messages_for_datetime_range($starttime, $endtime, $channel_id) {
$startTimeInUtcFormat = DateTimeUtil::convertDateTimeToUtcTimezoneTimestamp($starttime);
$endTimeInUtcFormat = DateTimeUtil::convertDateTimeToUtcTimezoneTimestamp($endtime);
- 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 get_channel_messages_for_datetime_range
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
function get_channel_messages_for_datetime_range($starttime, $endtime, $channel_id) {
$startTimeInUtcFormat = DateTimeUtil::convertDateTimeToUtcTimezoneTimestamp($starttime);
$endTimeInUtcFormat = DateTimeUtil::convertDateTimeToUtcTimezoneTimestamp($endtime);
Function get_slack_channels_list
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function get_slack_channels_list() {
if (function_exists("morgue_get_slack_channels_list")) {
return morgue_get_slack_channels_list();
} else {
$queryParam = 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"
Further reading
Function save_slack_channels_for_event
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static function save_slack_channels_for_event($event_id, $channel_id, $channel_name, $conn = null) {
$conn = $conn ?: Persistence::get_database_object();
if (is_null($conn)) {
return array("status" => self::ERROR,
"error" => "Couldn't get connection object.");
- 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
Similar blocks of code found in 4 locations. Consider refactoring. Open
static function get_channel($theid, $conn = null) {
$conn = $conn ?: Persistence::get_database_object();
$columns = array('id', 'channel');
$table_name = 'slack';
if (is_null($conn)) {
- 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 101.
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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Slack {
- Exclude checks
Opening brace of a class must be on the line after the definition Open
class Slack {
- Exclude checks
Visibility must be declared on method "get_channel" Open
static function get_channel($theid, $conn = null) {
- Exclude checks
Visibility must be declared on method "get_user_list" Open
function get_user_list() {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
if($userListData->ok != true ) {
- Exclude checks
Space found before closing bracket of FOREACH loop Open
foreach ($allMessages as $messages ) {
- Exclude checks
Blank line found at start of control structure Open
foreach ($messages as $message) {
- Exclude checks
Visibility must be declared on method "delete_channel" Open
static function delete_channel($theid, $conn = null) {
- Exclude checks
Visibility must be declared on method "undelete_channel" Open
static function undelete_channel($theid, $conn = null) {
- Exclude checks
Method name "Slack::get_channel_messages_for_datetime_range" is not in camel caps format Open
function get_channel_messages_for_datetime_range($starttime, $endtime, $channel_id) {
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Blank line found at end of control structure Open
- Exclude checks
Method name "Slack::delete_slack_channels_for_event" is not in camel caps format Open
static function delete_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Visibility must be declared on method "__construct" Open
function __construct(CurlClient $curlClient) {
- Exclude checks
Blank line found at start of control structure Open
foreach ($allMessages as $messages ) {
- Exclude checks
Method name "Slack::get_user_list" is not in camel caps format Open
function get_user_list() {
- Exclude checks
Method name "Slack::get_slack_channels_for_event" is not in camel caps format Open
static function get_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Method name "Slack::update_slack_channel_message" is not in camel caps format Open
static function update_slack_channel_message($channel_id, $message, $conn = null) {
- Exclude checks
Visibility must be declared on method "get_channel_messages_for_datetime_range" Open
function get_channel_messages_for_datetime_range($starttime, $endtime, $channel_id) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
foreach ($allMessages as $messages ) {
- Exclude checks
Visibility must be declared on method "delete_slack_channels_for_event" Open
static function delete_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Method name "Slack::delete_channel" is not in camel caps format Open
static function delete_channel($theid, $conn = null) {
- Exclude checks
Visibility must be declared on method "get_slack_channels_list" Open
function get_slack_channels_list() {
- Exclude checks
Method name "Slack::save_slack_channels_for_event" is not in camel caps format Open
static function save_slack_channels_for_event($event_id, $channel_id, $channel_name, $conn = null) {
- Exclude checks
Method name "Slack::undelete_channel" is not in camel caps format Open
static function undelete_channel($theid, $conn = null) {
- Exclude checks
Method name "Slack::get_slack_channels_list" is not in camel caps format Open
function get_slack_channels_list() {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
if($data->ok == true ) {
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Visibility must be declared on method "save_slack_channels_for_event" Open
static function save_slack_channels_for_event($event_id, $channel_id, $channel_name, $conn = null) {
- Exclude checks
Space found before comma in function call Open
array_push($allMessages , $sortedMessage);
- Exclude checks
Expected 1 space before "as"; 2 found Open
foreach ($allMessages as $messages ) {
- Exclude checks
Visibility must be declared on method "get_slack_channels_for_event" Open
static function get_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Visibility must be declared on method "update_slack_channel_message" Open
static function update_slack_channel_message($channel_id, $message, $conn = null) {
- Exclude checks
Expected 1 blank line at end of file; 2 found Open
}
- Exclude checks
Blank line found at start of control structure Open
while($fetch) {
- Exclude checks
Method name "Slack::get_channel" is not in camel caps format Open
static function get_channel($theid, $conn = null) {
- Exclude checks
Opening brace should be on a new line Open
function get_slack_channels_list() {
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Expected 1 space after CATCH keyword; 0 found Open
} catch(PDOException $e) {
- Exclude checks
Opening brace should be on a new line Open
function get_channel_messages_for_datetime_range($starttime, $endtime, $channel_id) {
- Exclude checks
Opening brace should be on a new line Open
static function delete_channel($theid, $conn = null) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($userListData->ok != true ) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($data->ok == true ) {
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Opening brace should be on a new line Open
static function save_slack_channels_for_event($event_id, $channel_id, $channel_name, $conn = null) {
- Exclude checks
Opening brace should be on a new line Open
function get_user_list() {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($fetchCounter > self::MAX_FETCH_LIMIT) {
- Exclude checks
Opening brace should be on a new line Open
static function get_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($data->ok != true) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if( (!isset($message->user))
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(isset(self::$user_list)) {
- Exclude checks
Opening brace should be on a new line Open
static function get_channel($theid, $conn = null) {
- Exclude checks
Opening brace should be on a new line Open
static function delete_slack_channels_for_event($event_id, $conn = null) {
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($fetch) {
- Exclude checks
Expected 1 space after CATCH keyword; 0 found Open
} catch(PDOException $e) {
- Exclude checks
Opening brace should be on a new line Open
static function update_slack_channel_message($channel_id, $message, $conn = null) {
- Exclude checks
Expected 0 spaces after opening bracket; 1 found Open
if( (!isset($message->user))
- Exclude checks
Opening brace should be on a new line Open
function __construct(CurlClient $curlClient) {
- Exclude checks
Opening brace should be on a new line Open
static function undelete_channel($theid, $conn = null) {
- Exclude checks