Passed
Push — master ( 4879bd...03e56f )
by Anthony
02:23
created

MissionsAleatoire   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B getTestCheckMission() 0 26 6
A setUpdateLastCheckMissions() 0 8 1
1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class MissionsAleatoire {
8
		
9
		
10
		
11
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
12
		public function __construct() {
13
			/*$dbc = App::getDb();
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
			$dbc1 = Bataille::getDb();*/
15
			
16
			//test si on a deje des missions dans la base
17
			$this->getTestCheckMission();
18
		}
19
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
20
		
21
		
22
		
23
		//-------------------------- GETTER ----------------------------------------------------------------------------//
24
		/**
25
		 * fonction qui regarde la derniere fois que la récupération de missions a été effectuée.
26
		 * Si jamais fait on ajoute la date du jour en bdd et on lance la récupération de missions
27
		 * sinon si elle est supérieur a 1 jour on la remet a la date du jour + on get de nouvelles missions
28
		 */
29
		private function getTestCheckMission() {
30
			$dbc = App::getDb();
31
			
32
			$query = $dbc->select("last_check_mission")->from("_bataille_base")->where("ID_base", "=", Bataille::getIdBase())->get();
33
			
34
			if (is_array($query) && (count($query) == 1)) {
35
				foreach ($query as $obj) {
36
					$last_check_mission = $obj->last_check_mission;
37
				}
38
				
39
				if ($last_check_mission == "") {
40
					$this->setUpdateLastCheckMissions();
41
				}
42
				else {
43
					$today = new \DateTime();
44
					$last_check_mission = new \DateTime($last_check_mission);
0 ignored issues
show
Bug introduced by
The variable $last_check_mission does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
45
					$interval = $last_check_mission->diff($today);
46
					
47
					$diff_jour = explode("+", $interval->format("%R%a"))[1];
48
					
49
					if ($diff_jour >= 1) {
50
						$this->setUpdateLastCheckMissions();
51
					}
52
				}
53
			}
54
		}
55
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
56
		
57
		
58
		
59
		//-------------------------- SETTER ----------------------------------------------------------------------------//
60
		/**
61
		 * fonction qui met a jour le last_ckeck_missions dans _bataille_base
62
		 * le met à la date du jour
63
		 */
64
		public function setUpdateLastCheckMissions() {
65
			$dbc = App::getDb();
66
			
67
			$dbc->update("last_check_mission", date("Y-m-d"))
68
				->from("_bataille_base")
69
				->where("ID_base", "=", Bataille::getIdBase())
70
				->set();
71
		}
72
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
73
		
74
	}