Completed
Push — master ( eef885...465d0c )
by
unknown
30:08 queued 12:49
created

Helper_Class   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_model() 0 3 1
A __toString() 0 5 1
B delete_model_for_print() 0 16 6
1
<?php
2
/**
3
 * Classe helper pour les modèles.
4
 *
5
 * @author Jimmy Latour <[email protected]>
6
 * @since 1.0.0.0
7
 * @version 1.3.0.0
8
 * @copyright 2015-2017
9
 * @package wpeo_model
10
 * @subpackage class
11
 */
12
13
namespace eoxia;
14
15
if ( ! defined( 'ABSPATH' ) ) { exit; }
16
17
if ( ! class_exists( '\eoxia\Helper_Class' ) ) {
18
19
	/**
20
	 * Classe helper pour les modèles.
21
	 */
22
	class Helper_Class {
23
24
		/**
25
		 * Récupères le modèle.
26
		 *
27
		 * @since 1.0.0.0
28
		 * @version 1.3.0.0
29
		 *
30
		 * @return Object le modèle.
31
		 */
32
		public function get_model() {
33
			return $this->model;
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
		}
35
36
		/**
37
		 * Permet de faire echo sur un objet et supprimes la définition du modèle avant l'affichage.
38
		 *
39
		 * @return string void
40
		 */
41
		public function __toString() {
42
			$this->delete_model_for_print( $this );
43
			echo '<pre>'; print_r( $this ); echo '</pre>';
44
			return '';
45
		}
46
47
		/**
48
		 * Supprime le modèle.
49
		 *
50
		 * @since 1.0.0.0
51
		 * @version 1.3.0.0
52
		 *
53
		 * @param  object $current L'objet complet.
54
		 */
55
		private function delete_model_for_print( $current ) {
56
			if ( ! empty( $this->model ) ) {
57
				unset( $this->model );
58
			}
59
60
			foreach ( $current as &$content ) {
61
				if ( is_array( $content ) ) {
62
					foreach ( $content as &$model ) {
63
						if ( ! empty( $model->model ) ) {
64
							unset( $model->model );
65
							$this->delete_model_for_print( $model );
66
						}
67
					}
68
				}
69
			}
70
		}
71
	}
72
} // End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
73