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

Post_Class::search()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 22
nc 5
nop 2
dl 0
loc 36
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Gestion des posts (POST, PUT, GET, DELETE)
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' ) ) {
16
	exit;
17
}
18
19
if ( ! class_exists( '\eoxia\Post_Class' ) ) {
20
	/**
21
	 * Gestion des posts (POST, PUT, GET, DELETE)
22
	 */
23
	class Post_Class extends Singleton_Util {
24
		/**
25
		 * Le nom du modèle
26
		 *
27
		 * @var string
28
		 */
29
		protected $model_name = 'post_model';
30
31
		/**
32
		 * Le type du post
33
		 *
34
		 * @var string
35
		 */
36
		protected $post_type = 'post';
37
38
		/**
39
		 * La clé principale pour post_meta
40
		 *
41
		 * @var string
42
		 */
43
		protected $meta_key = '_wpeo_post';
44
45
		/**
46
		 * Le nom pour le resgister post type
47
		 *
48
		 * @var string
49
		 */
50
		protected $post_type_name = 'posts';
51
52
		/**
53
		 * Utiles pour récupérer la clé unique
54
		 *
55
		 * @todo Rien à faire ici
56
		 * @var string
57
		 */
58
		protected $identifier_helper = 'post';
59
60
		/**
61
		 * Fonction de callback après avoir récupérer le modèle en mode GET.
62
		 *
63
		 * @var array
64
		 */
65
		protected $after_get_function = array();
66
67
		/**
68
		 * Fonction de callback avant d'insérer les données en mode POST.
69
		 *
70
		 * @var array
71
		 */
72
		protected $before_post_function = array();
73
74
		/**
75
		 * Fonction de callback avant de dispacher les données en mode POST.
76
		 *
77
		 * @var array
78
		 */
79
		protected $before_model_post_function = array();
80
81
		/**
82
		 * Fonction de callback après avoir inséré les données en mode POST.
83
		 *
84
		 * @var array
85
		 */
86
		protected $after_post_function = array();
87
88
		/**
89
		 * Fonction de callback avant de mêttre à jour les données en mode PUT.
90
		 *
91
		 * @var array
92
		 */
93
		protected $before_put_function = array();
94
95
		/**
96
		 * Fonction de callback avant de dispatcher les données en mode PUT.
97
		 *
98
		 * @var array
99
		 */
100
		protected $before_model_put_function = array();
101
102
		/**
103
		 * Fonction de callback après avoir mis à jour les données en mode PUT.
104
		 *
105
		 * @var array
106
		 */
107
		protected $after_put_function = array();
108
109
		/**
110
		 * Appelle l'action "init" de WordPress
111
		 *
112
		 * @return void
113
		 */
114
		protected function construct() {
115
			add_action( 'init', array( $this, 'init_post_type' ) );
116
		}
117
118
		/**
119
		 * Initialise le post type selon $name et $name_singular.
120
		 * Initialise la taxonomy si elle existe.
121
		 *
122
		 * @see register_post_type
123
		 * @return boolean
124
		 *
125
		 * @since 1.0.0.0
126
		 * @version 1.3.0.0
127
		 */
128
		public function init_post_type() {
129
			$args = array(
130
				// 'public' => Config_Util::$init['digirisk']->debug ? true : false,
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
131
				'label'  => $this->post_type_name,
132
			);
133
134
			$return = register_post_type( $this->post_type, $args );
135
			Log_Class::g()->exec( 'digi_post_type', '', 'Enregistres le post personnalisé : ' . $this->post_type, $args );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method exec() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\External_Util, eoxia\Init_Util, eoxia\View_Util, eoxia\log_class. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
136
137
			if ( ! empty( $this->attached_taxonomy_type ) ) {
138
				register_taxonomy( $this->attached_taxonomy_type, $this->post_type );
0 ignored issues
show
Bug introduced by
The property attached_taxonomy_type 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...
139
				Log_Class::g()->exec( 'digi_taxonomy', '', 'Enregistres la taxonomie : ' . $this->attached_taxonomy_type );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method exec() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\External_Util, eoxia\Init_Util, eoxia\View_Util, eoxia\log_class. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
140
			}
141
142
			return $return;
143
		}
144
145
		/**
146
		 * Permet de récupérer le schéma avec les données du modèle par défault.
147
		 *
148
		 * @since 1.0.0.0
149
		 * @version 1.3.0.0
150
		 *
151
		 * @return Object
152
		 */
153
		public function get_schema() {
154
			$model_name = $this->model_name;
155
			$model = new $model_name( array() );
156
			return $model->get_model();
157
		}
158
159
		/**
160
		 * Récupères les données selon le modèle définis.
161
		 *
162
		 * @since 1.0.0.0
163
		 * @version 1.3.0.0
164
		 *
165
		 * @param array   $args Les paramètres de get_comments @https://codex.wordpress.org/Function_Reference/WP_Query.
166
		 * @param boolean $single Si on veut récupérer un tableau, ou qu'une seule entrée.
167
		 *
168
		 * @return Object
169
		 *
170
		 * @todo: ligne 128 - Temporaire
171
		 */
172
		public function get( $args = array(
173
				'posts_per_page' => -1,
174
			), $single = false ) {
175
176
			$array_posts = array();
177
			$args['post_type'] = $this->post_type;
178
179
			if ( ! empty( $args['include'] ) ) {
180
				$args['post__in'] = $args['include'];
181
				if ( ! is_array( $args['post__in'] ) ) {
182
					$args['post__in'] = (array) $args['post__in'];
183
				}
184
				unset( $args['include'] );
185
			}
186
187
			if ( ! isset( $args['posts_per_page'] ) ) {
188
				$args['posts_per_page'] = -1;
189
			}
190
191
			if ( isset( $args['id'] ) ) {
192
				$array_posts[] = get_post( $args['id'], ARRAY_A );
193
				unset( $args['id'] );
194
			} elseif ( isset( $args['schema'] ) ) {
195
				$array_posts[] = array();
196
			} else {
197
				$query_posts = new \WP_Query( $args );
198
				$array_posts = $query_posts->posts;
199
				unset( $query_posts->posts );
200
			}
201
202
			foreach ( $array_posts as $key => $post ) {
203
				$post = (array) $post;
204
205
				// Si post['ID'] existe, on récupère les meta.
206
				if ( ! empty( $post['ID'] ) ) {
207
					$list_meta = get_post_meta( $post['ID'] );
208
					foreach ( $list_meta as &$meta ) {
209
						$meta = array_shift( $meta );
210
						$meta = JSON_Util::g()->decode( $meta );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method decode() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\JSON_Util. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
211
					}
212
213
					$post = array_merge( $post, $list_meta );
214
215
					if ( ! empty( $post[ $this->meta_key ] ) ) {
216
						$data_json = JSON_Util::g()->decode( $post[ $this->meta_key ] );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method decode() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\JSON_Util. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
217
						if ( is_array( $data_json ) ) {
218
							$post = array_merge( $post, $data_json );
219
						} else {
220
							$post[ $this->meta_key ] = $data_json;
221
						}
222
						unset( $post[ $this->meta_key ] );
223
					}
224
				}
225
226
				$model_name = $this->model_name;
227
				$array_posts[ $key ] = new $model_name( $post );
228
				$array_posts[ $key ] = $this->get_taxonomies_id( $array_posts[ $key ] );
229
230
				$array_posts[ $key ] = Model_Util::exec_callback( $array_posts[ $key ], $this->after_get_function );
231
			} // End foreach().
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...
232
233
			if ( true === $single && 1 === count( $array_posts ) ) {
234
				$array_posts = $array_posts[0];
235
			}
236
237
			return $array_posts;
238
		}
239
240
		/**
241
		 * Appelle la méthode update.
242
		 *
243
		 * @since 1.0.0.0
244
		 * @version 1.3.0.0
245
		 *
246
		 * @param  Array $data Les données.
247
		 * @return Array $data Les données
248
		 */
249
		public function create( $data ) {
250
			return $this->update( $data );
251
		}
252
253
		/**
254
		 * Insère ou met à jour les données dans la base de donnée.
255
		 *
256
		 * @since 1.0.0.0
257
		 * @version 1.3.0.0
258
		 *
259
		 * @param  Array $data Les données a insérer ou à mêttre à jour.
260
		 * @return Object      L'objet construit grâce au modèle.
261
		 */
262
		public function update( $data ) {
263
			$model_name = $this->model_name;
264
			$data = (array) $data;
265
266
			if ( empty( $data['id'] ) ) {
267
				$data = Model_Util::exec_callback( $data, $this->before_model_post_function );
268
269
				$data = new $model_name( $data );
270
271
				// Ajout du post type si il est vide !
272
				if ( empty( $data->type ) ) {
273
					$data->type = $this->post_type;
274
				}
275
276
				$data = Model_Util::exec_callback( $data, $this->before_post_function );
277
278
				if ( ! empty( $data->error ) && $data->error ) {
279
					return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by eoxia\Post_Class::update of type object.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
280
				}
281
282
				$post_save = wp_insert_post( $data->do_wp_object(), true );
283
284
				if ( ! is_wp_error( $post_save ) ) {
285
					$data->id = $post_save;
286
				} else {
287
					$data = $post_save;
288
				}
289
290
				if ( ! is_wp_error( $data ) ) {
291
					Save_Meta_Class::g()->save_meta_data( $data, 'update_post_meta', $this->meta_key );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method save_meta_data() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\Save_Meta_Class. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
292
					// Save taxonomy!
293
					$this->save_taxonomies( $data );
294
				}
295
296
				$data = Model_Util::exec_callback( $data, $this->after_post_function );
297
			} else {
298
				$data = Model_Util::exec_callback( $data, $this->before_model_put_function );
299
300
				$current_data = $this->get( array(
301
					'id' => $data['id'],
302
				), true );
303
				$obj_merged = (object) array_merge( (array) $current_data, (array) $data );
304
				$data = new $model_name( (array) $obj_merged );
305
				$data->type = $this->post_type;
306
307
				$data = Model_Util::exec_callback( $data, $this->before_put_function );
308
309
				if ( ! empty( $data->error ) && $data->error ) {
310
					return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by eoxia\Post_Class::update of type object.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
311
				}
312
313
				$post_save = wp_update_post( $data->do_wp_object(), true );
314
				if ( is_wp_error( $post_save ) ) {
315
					$data = $post_save;
316
				}
317
318
				if ( ! is_wp_error( $data ) ) {
319
					Save_Meta_Class::g()->save_meta_data( $data, 'update_post_meta', $this->meta_key );
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class eoxia\Singleton_Util as the method save_meta_data() does only exist in the following sub-classes of eoxia\Singleton_Util: eoxia\Save_Meta_Class. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
320
					// Save taxonomy!
321
					$this->save_taxonomies( $data );
322
				}
323
324
				$data = Model_Util::exec_callback( $data, $this->after_put_function );
325
			} // 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...
326
327
328
329
			return $data;
330
		}
331
332
		/**
333
		 * Recherche dans les meta value.
334
		 *
335
		 * @since 1.0.0.0
336
		 * @version 1.3.0.0
337
		 *
338
		 * @param string $search Le terme de la recherche.
339
		 * @param array  $array  La définition de la recherche.
340
		 *
341
		 * @return array
342
		 */
343
		public function search( $search, $array ) {
344
			global $wpdb;
345
346
			if ( empty( $array ) || ! is_array( $array ) ) {
347
				return array();
348
			}
349
350
			$where = ' AND ( ';
351
			if ( ! empty( $array ) ) {
352
				foreach ( $array as $key => $element ) {
353
					if ( is_array( $element ) ) {
354
						foreach ( $element as $sub_element ) {
355
							$where .= ' AND ( ' === $where  ? '' : ' OR ';
356
							$where .= ' (PM.meta_key="' . $sub_element . '" AND PM.meta_value LIKE "%' . $search . '%") ';
357
						}
358
					} else {
359
						$where .= ' AND ( ' === $where ? '' : ' OR ';
360
						$where .= ' P.' . $element . ' LIKE "%' . $search . '%" ';
361
					}
362
				}
363
			}
364
365
			$where .= ' ) ';
366
367
			$list_group = $wpdb->get_results( "SELECT DISTINCT P.ID FROM {$wpdb->posts} as P JOIN {$wpdb->postmeta} AS PM ON PM.post_id=P.ID WHERE P.post_type='" . $this->get_post_type() . "'" . $where );
368
			$list_model = array();
369
			if ( ! empty( $list_group ) ) {
370
				foreach ( $list_group as $element ) {
371
					$list_model[] = $this->get( array(
372
						'id' => $element->ID,
373
					) );
374
				}
375
			}
376
377
			return $list_model;
378
		}
379
380
		/**
381
		 * Retourne le post type
382
		 *
383
		 * @since 1.0.0.0
384
		 * @version 1.3.0.0
385
		 *
386
		 * @return string Le post type
387
		 */
388
		public function get_post_type() {
389
			return $this->post_type;
390
		}
391
392
		/**
393
		 * Utile uniquement pour DigiRisk.
394
		 *
395
		 * @since 1.0.0.0
396
		 * @version 1.3.0.0
397
		 *
398
		 * @return string L'identifiant des commentaires pour DigiRisk.
399
		 */
400
		public function get_identifier_helper() {
401
			return $this->identifier_helper;
402
		}
403
404
		/**
405
		 * Récupères les ID des taxonomies lié à ce post.
406
		 *
407
		 * @param  object $data L'objet courant.
408
		 * @return object				L'objet avec les taxonomies.
409
		 *
410
		 * @since 1.0.0.0
411
		 * @version 1.3.0.0
412
		 */
413
		private function get_taxonomies_id( $data ) {
414
			$model = $data->get_model();
415
			if ( ! empty( $model['taxonomy']['child'] ) ) {
416
				foreach ( $model['taxonomy']['child'] as $key => $value ) {
417
					$data->taxonomy[ $key ] = wp_get_object_terms( $data->id, $key, array(
418
						'fields' => 'ids',
419
					) );
420
				}
421
			}
422
423
			return $data;
424
		}
425
426
		/**
427
		 * Sauvegardes les taxonomies
428
		 *
429
		 * @param  object $data L'objet avec les taxonomies à sauvegarder.
430
		 */
431
		private function save_taxonomies( $data ) {
432
			if ( ! empty( $data->taxonomy ) ) {
433
				foreach ( $data->taxonomy as $taxonomy_name => $taxonomy_data ) {
434
					if ( ! empty( $taxonomy_name ) ) {
435
						wp_set_object_terms( $data->id, $taxonomy_data, $taxonomy_name, true );
436
					}
437
				}
438
			}
439
		}
440
441
		/**
442
		 * Permet de changer le modèle en dur.
443
		 *
444
		 * @param string $model_name Le nom du modèle.
445
		 *
446
		 * @since 1.0.0.0
447
		 * @version 1.3.6.0
448
		 */
449
		public function set_model( $model_name ) {
450
			$this->model_name = $model_name;
451
		}
452
	}
453
} // 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...
454