File class.Game.php
has 285 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
class Game extends Ork3 {
public function __construct() {
Game
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class Game extends Ork3 {
public function __construct() {
parent::__construct();
$this->game = new yapo($this->db, DB_PREFIX . 'game');
Method set_flag_capture_state
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function set_flag_capture_state($game_id, $objective_id, $state) {
$game = $this->GetGame(array('GameId' => $game_id));
$obj = $this->GetObjective(array('ObjectiveId' => $objective_id));
if (count($game) == 0) return false;
Function set_game_state
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function set_game_state($game_id, $objective_id, $state) {
if (valid_id($game_id) && valid_id($objective_id)) {
$this->objective->game_objective_id = $objective_id;
if ($this->objective->find() && $this->game->game_objective_id == $objective_id) {
$this->objective->state = json_encode($state);
- 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 if_state
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function if_state($state_requirements, $state_source, $state_lookup, $if_match) {
foreach ($state_requirements as $state_var => $value) {
if (is_array($value)) {
$comp = $value['Comparator'];
if (!$comp($state_lookup($state_source, $stat_var), $value['Value'])) return 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 create_game
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function create_game($name, $type, $mundane_id, $configuration, $state) {
Function GetObjectives
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function GetObjectives($request) {
$objectives = array();
if (valid_id($request['GameId'])) {
$this->objective->clear();
$this->objective->game_id = $request['GameId'];
- 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 ValidateGameMaster
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function ValidateGameMaster($request) {
if ($this->game_security($request['GameId'], $request['Code'])) {
if (($mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token'])) > 0) {
$this->game->clear();
$this->game->game_id = $request['GameId'];
- 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 too many return
statements within this method. Open
return $State['TeamId'];
Avoid too many return
statements within this method. Open
return count($Objective)>0;
Function GetGameState
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function GetGameState($request) {
if (valid_id($request['GameId']) && valid_id($request['ObjectiveId'])) {
$x = $this->GetObjective($request);
} else if (valid_id($request['GameId'])) {
$x = $this->GetGame($request);
- 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 2 locations. Consider refactoring. Open
public function __construct() {
parent::__construct();
$this->game = new yapo($this->db, DB_PREFIX . 'game');
$this->team = new yapo($this->db, DB_PREFIX . 'game_team');
$this->objective = new yapo($this->db, DB_PREFIX . 'game_objective');
- 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 95.
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