WordPressQueryProvider   D
last analyzed

Complexity

Total Complexity 114

Size/Duplication

Total Lines 891
Duplicated Lines 28.73 %

Coupling/Cohesion

Components 2
Dependencies 9

Importance

Changes 0
Metric Value
wmc 114
lcom 2
cbo 9
dl 256
loc 891
rs 4.4444
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A handlesOrderedPaging() 0 4 1
A getExpressionProvider() 0 8 2
C getResourceSet() 30 70 16
D getResourceFromResourceSet() 34 98 17
D getRelatedResourceSet() 78 157 27
D getResourceFromRelatedResourceSet() 54 122 15
C getRelatedResourceReference() 0 69 12
A _serializePosts() 0 9 2
B _serializePost() 24 54 5
A _serializeTags() 9 9 2
A _serializeTag() 0 9 1
A _serializeCategories() 9 9 2
A _serializeCategory() 0 9 1
A _serializeComments() 0 9 2
B _serializeComment() 12 33 3
A _serializeUsers() 0 9 2
A _serializeUser() 6 20 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like WordPressQueryProvider often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use WordPressQueryProvider, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 7.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use POData\UriProcessor\ResourcePathProcessor\SegmentParser\KeyDescriptor;
4
use POData\Providers\Metadata\ResourceSet;
5
use POData\Providers\Metadata\ResourceProperty;
6
use POData\Providers\Query\IQueryProvider;
7
require_once "WordPressMetadata.php";
8
require_once "POData\Providers\Query\IDataServiceQueryProvider2.php";
9
10
/** The name of the database for WordPress */
11
define('DB_NAME', 'wordpress');
12
13
/** MySQL database username */
14
define('DB_USER', 'root');
15
16
/** MySQL database password */
17
define('DB_PASSWORD', 'root');
18
19
/** MySQL hostname */
20
define('DB_HOST', 'localhost');
21
22
23
class WordPressQueryProvider implements IQueryProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    /**
26
     * Handle to connection to Database     
27
     */
28
    private $_connectionHandle = null;
29
30
    /**
31
     * Reference to the custom expression provider
32
     *
33
     * @var NorthWindDSExpressionProvider
34
     */
35
    private $_wordPressMySQLExpressionProvider;
36
    
37
    /**
38
     * Constructs a new instance of WordPressQueryProvider
39
     * 
40
     */
41
    public function __construct()
42
    {
43
        $this->_connectionHandle = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true);
44
        if ( $this->_connectionHandle ) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
45
        } else {             
46
             die(print_r(mysql_error(), true));
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
47
        } 
48
49
        mysql_select_db(DB_NAME, $this->_connectionHandle);
50
    }
51
52
    /**
53
     * (non-PHPdoc)
54
     * @see POData\Providers\Query.IQueryProvider::canApplyQueryOptions()
55
     */
56
    public function handlesOrderedPaging()
57
    {
58
        return true;
59
    }
60
61
    /**
62
     * (non-PHPdoc)
63
     * @see POData\Providers\Query.IQueryProvider::getExpressionProvider()
64
     */
65
    public function getExpressionProvider()
66
    {
67
    	if (is_null($this->_wordPressMySQLExpressionProvider)) {
68
    		$this->_wordPressMySQLExpressionProvider = new WordPressDSExpressionProvider();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \WordPressDSExpressionProvider() of type object<WordPressDSExpressionProvider> is incompatible with the declared type object<NorthWindDSExpressionProvider> of property $_wordPressMySQLExpressionProvider.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
69
    	}
70
    	
71
    	return $this->_wordPressMySQLExpressionProvider;
72
    }
73
    
74
    /**
75
     * Gets collection of entities belongs to an entity set
76
     * 
77
     * @param ResourceSet      $resourceSet   The entity set whose 
78
     *                                        entities needs to be fetched
79
     * @param string           $filterOption  Contains the filter condition
0 ignored issues
show
Documentation introduced by
There is no parameter named $filterOption. Did you maybe mean $filter?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
80
     * @param string           $select        For future purpose,no need to pass it
81
     * @param string           $orderby       For future purpose,no need to pass it
82
     * @param string           $top           For future purpose,no need to pass it
83
     * @param string           $skip          For future purpose,no need to pass it
84
     * 
85
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
86
     */
87
    public function getResourceSet(ResourceSet $resourceSet,$filter=null,$select=null,$orderby=null,$top=null,$skip=null)
88
    {   
89
        $resourceSetName =  $resourceSet->getName();
90 View Code Duplication
        if ($resourceSetName !== 'Posts' 
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
            && $resourceSetName !== 'Tags' 
92
            && $resourceSetName !== 'Categories' 
93
            && $resourceSetName !== 'Comments' 
94
            && $resourceSetName !== 'Users'
95
        ) {
96
            die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
97
        }
98
99
       
100
        $returnResult = array();
101
        switch ($resourceSetName) {
102
        case 'Posts':
103
            $query = "SELECT * FROM `wp_posts` WHERE"
104
                   ." wp_posts.post_type = 'post'"
105
                   ." AND wp_posts.post_status = 'publish'";
106
            if ($filter !== null) {
107
                $query .= " AND $filter";
108
            }
109
            $stmt = mysql_query($query); 
110
            $returnResult = $this->_serializePosts($stmt);     
111
            break;                   
112 View Code Duplication
        case 'Tags':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
            $query = "SELECT t.*, tt.description"
114
                   ." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt"
115
                   ." ON tt.term_id = t.term_id"
116
                   ." WHERE tt.taxonomy = 'post_tag'";
117
            if ($filter !== null) {
118
                $query .= " AND $filter";
119
            }
120
            $stmt = mysql_query($query);
121
            $returnResult = $this->_serializeTags($stmt);       
122
            break;
123 View Code Duplication
        case 'Categories':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
            $query = "SELECT t.*, tt.description"
125
                   ." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt"
126
                   ." ON tt.term_id = t.term_id"
127
                   ." WHERE tt.taxonomy = 'category'";
128
            if ($filter !== null) {
129
                $query .= " AND $filter";
130
            }
131
            $stmt = mysql_query($query);
132
            $returnResult = $this->_serializeCategories($stmt);       
133
            break;
134
        case 'Comments':
135
            $query = "SELECT * FROM `wp_comments` WHERE"
136
                   ." wp_comments.comment_approved = 1";
137
            if ($filter !== null) {
138
                $query .= " AND $filter";
139
            }
140
            $stmt = mysql_query($query);
141
            $returnResult = $this->_serializeComments($stmt);       
142
            break;
143
        case 'Users':
144
            $query = "SELECT * FROM `wp_users`";
145
            //print "<br>Filter:".$filter;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
146
            if ($filter !== null) {
147
                $query .= " AND $filter";
148
            }
149
            $stmt = mysql_query($query);
150
            //$data = mysql_fetch_assoc($stmt);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
151
            $returnResult = $this->_serializeUsers($stmt);
152
            break;
153
        }
154
        mysql_free_result($stmt);
0 ignored issues
show
Bug introduced by
The variable $stmt 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...
155
        return $returnResult;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $returnResult; (array) is incompatible with the return type declared by the interface POData\Providers\Query\I...rovider::getResourceSet of type POData\Providers\Query\QueryResult.

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...
156
    }
157
    
158
    /**
159
     * Gets an entity instance from an entity set identifed by a key
160
     * 
161
     * @param ResourceSet   $resourceSet   The entity set from which an entity 
162
     *                                     needs to be fetched
163
     * @param KeyDescriptor $keyDescriptor The key to identify the entity 
164
     *                                     to be fetched
165
     * 
166
     * @return object|null Returns entity instance if found else null
167
     */
168
    public function getResourceFromResourceSet(ResourceSet $resourceSet, KeyDescriptor $keyDescriptor)
169
    {
170
        $resourceSetName =  $resourceSet->getName();
171 View Code Duplication
        if ($resourceSetName !== 'Posts' 
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
            && $resourceSetName !== 'Tags' 
173
            && $resourceSetName !== 'Categories' 
174
            && $resourceSetName !== 'Comments' 
175
            && $resourceSetName !== 'Users'
176
        ) {
177
            die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
178
        }
179
180
        $namedKeyValues = $keyDescriptor->getValidatedNamedValues();
181
        $keys = array();
182
        foreach ($namedKeyValues as $key => $value) {
183
            $keys[] = "$key = '$value[0]' ";
184
        }
185
        $conditionStr = implode(' AND ', $keys);
0 ignored issues
show
Unused Code introduced by
$conditionStr is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
        
187
        switch ($resourceSetName) {
188
        case 'Posts':
189
            $query = "SELECT * FROM `wp_posts` WHERE"
190
                   ." wp_posts.post_type = 'post'"
191
                   ." AND wp_posts.post_status = 'publish'"
192
                   ." AND wp_posts.ID = ".$namedKeyValues['PostID'][0];
193
            $stmt = mysql_query($query);
194
              
195
            //If resource not found return null to the library
196
            if (!mysql_num_rows($stmt)) {
197
                return null;
198
            } 
199
              
200
            $data = mysql_fetch_assoc($stmt);
201
            $result = $this->_serializePost($data);
202
            break;
203
        case 'Tags':
204
            $query = "SELECT t.*, tt.description"
205
                   ." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt"
206
                   ." ON tt.term_id = t.term_id"
207
                   ." WHERE tt.taxonomy = 'post_tag'"
208
                   ." AND t.term_id = ".$namedKeyValues['TagID'][0];
209
            $stmt = mysql_query($query);
210
              
211
            //If resource not found return null to the library
212
            if (!mysql_num_rows($stmt)) {
213
                return null;
214
            }
215
              
216
            $data = mysql_fetch_assoc($stmt);
217
            $result = $this->_serializeTag($data);
218
            break;
219
        case 'Categories':
220
            $query = "SELECT t.*, tt.description"
221
                   ." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt"
222
                   ." ON tt.term_id = t.term_id"
223
                   ." WHERE tt.taxonomy = 'category'"
224
                   ." AND t.term_id = ".$namedKeyValues['CategoryID'][0];
225
            $stmt = mysql_query($query);
226
              
227
            //If resource not found return null to the library
228
            if (!mysql_num_rows($stmt)) {
229
                return null;
230
            }
231
              
232
            $data = mysql_fetch_assoc($stmt);
233
            $result = $this->_serializeCategory($data);
234
            break;
235 View Code Duplication
        case 'Comments':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
236
            $query = "SELECT * FROM `wp_comments`"
237
                   ." WHERE comment_approved = 1" 
238
                   ." AND comment_ID = ".$namedKeyValues['CommentID'][0];
239
            $stmt = mysql_query($query);
240
              
241
            //If resource not found return null to the library
242
            if (!mysql_num_rows($stmt)) {
243
                return null;
244
            }
245
              
246
            $data = mysql_fetch_assoc($stmt);
247
            $result = $this->_serializeComment($data);
248
            break;
249 View Code Duplication
        case 'Users':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
            $query = "SELECT * FROM `wp_users` WHERE ID = ".$namedKeyValues['UserID'][0];
251
            $stmt = mysql_query($query);
252
              
253
            //If resource not found return null to the library
254
            if (!mysql_num_rows($stmt)) {
255
                return null;
256
            }
257
              
258
            $data = mysql_fetch_assoc($stmt);
259
            $result = $this->_serializeUser($data);
260
            break;
261
        }
262
        
263
        mysql_free_result($stmt);
0 ignored issues
show
Bug introduced by
The variable $stmt 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...
264
        return $result;
0 ignored issues
show
Bug introduced by
The variable $result 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...
265
    }
266
    
267
    /**
268
     * Get related resource set for a resource
269
     * 
270
     * @param ResourceSet      $sourceResourceSet    The source resource set
271
     * @param mixed            $sourceEntityInstance The resource
272
     * @param ResourceSet      $targetResourceSet    The resource set of 
273
     *                                               the navigation property
274
     * @param ResourceProperty $targetProperty       The navigation property to be 
275
     *                                               retrieved
276
     * @param string           $filterOption         Contains the filter condition
0 ignored issues
show
Documentation introduced by
There is no parameter named $filterOption. Did you maybe mean $filter?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
277
     * @param string           $select               For future purpose,no need to pass it
278
     * @param string           $orderby              For future purpose,no need to pass it
279
     * @param string           $top                  For future purpose,no need to pass it
280
     * @param string           $skip                 For future purpose,no need to pass it
281
     *                                               
282
     * @return object[] Array of related resource if exists, if no 
283
     *                                related resources found returns empty array
284
     */
285
    public function  getRelatedResourceSet(ResourceSet $sourceResourceSet, 
286
        $sourceEntityInstance, 
287
        ResourceSet $targetResourceSet,
288
        ResourceProperty $targetProperty,
289
        $filter=null ,$select=null, $orderby=null, $top=null, $skip=null
290
    ) {
291
        $result = array();
292
        $srcClass = get_class($sourceEntityInstance);
293
        $navigationPropName = $targetProperty->getName();
294
        
295
        switch (true) {
296
        case ($srcClass == 'Post'):
297
            if ($navigationPropName == 'Tags') {
298
                $query = "SELECT t.*, tt.description"
299
                       ." FROM wp_terms AS t"
300
                       ." INNER JOIN wp_term_taxonomy AS tt"
301
                       ." ON tt.term_id = t.term_id"
302
                       ." INNER JOIN wp_term_relationships AS tr"
303
                       ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
304
                       ." WHERE tt.taxonomy IN ('post_tag')"
305
                       ." AND tr.object_id IN ($sourceEntityInstance->PostID)";
306
                if ($filter !== null) {
307
                    $query .= " AND $filter";
308
                }
309
                $stmt = mysql_query($query);
310
                if ( $stmt === false) {
311
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
312
                }
313
                        
314
                $result = $this->_serializeTags($stmt);
315
            } elseif ($navigationPropName == 'Categories') {
316
                $query = "SELECT t.*, tt.description"
317
                       ." FROM wp_terms AS t"
318
                       ." INNER JOIN wp_term_taxonomy AS tt"
319
                       ." ON tt.term_id = t.term_id"
320
                       ." INNER JOIN wp_term_relationships AS tr"
321
                       ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
322
                       ." WHERE tt.taxonomy IN ('category')"
323
                       ." AND tr.object_id IN ($sourceEntityInstance->PostID)";
324
                if ($filter !== null) {
325
                    $query .= " AND $filter";
326
                }
327
                $stmt = mysql_query($query);
328
                if ( $stmt === false) {            
329
                       die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
330
                }
331
                        
332
                $result = $this->_serializeCategories($stmt);
333 View Code Duplication
            } else if ($navigationPropName == 'Comments') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
334
                $query = "SELECT * FROM `wp_comments`"
335
                       ." WHERE comment_approved = 1" 
336
                       ." AND comment_post_ID = $sourceEntityInstance->PostID";
337
                if ($filter !== null) {
338
                    $query .= " AND $filter";
339
                }
340
                $stmt = mysql_query($query);
341
                if ( $stmt === false) {
342
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
343
                }
344
                        
345
                $result = $this->_serializeComments($stmt);
346
            } else {
347
                die('Post does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
348
            }
349
            break;
350
351 View Code Duplication
        case ($srcClass == 'Tag'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
            if ($navigationPropName == 'Posts') {
353
                $query = "SELECT p . *" 
354
                         ." FROM wp_posts AS p"
355
                         ." INNER JOIN wp_term_relationships AS tr"
356
                         ." ON p.ID = tr.object_id"
357
                         ." INNER JOIN wp_term_taxonomy AS tt"
358
                         ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
359
                         ." WHERE tt.term_id = $sourceEntityInstance->TagID"
360
                         ." AND p.post_type = 'post'"
361
                         ." AND p.post_status = 'publish'";
362
                if ($filter !== null) {
363
                    $query .= " AND $filter";
364
                }
365
                $stmt = mysql_query($query);
366
                if ( $stmt === false) {
367
                            die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
368
                }
369
                        
370
                      $result = $this->_serializePosts($stmt);
371
            } else {
372
                die('Tag does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
373
            }
374
            break;
375
                    
376 View Code Duplication
        case ($srcClass == 'Category'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
            if ($navigationPropName == 'Posts') {
378
                $query = "SELECT p . *" 
379
                         ." FROM wp_posts AS p"
380
                         ." INNER JOIN wp_term_relationships AS tr"
381
                         ." ON p.ID = tr.object_id"
382
                         ." INNER JOIN wp_term_taxonomy AS tt"
383
                         ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
384
                         ." WHERE tt.term_id = $sourceEntityInstance->CategoryID"
385
                         ." AND p.post_type = 'post'"
386
                         ." AND p.post_status = 'publish'";
387
                if ($filter !== null) {
388
                    $query .= " AND $filter";
389
                }
390
                $stmt = mysql_query($query);
391
                if ( $stmt === false) {
392
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
393
                }
394
                        
395
                $result = $this->_serializePosts($stmt);
396
            } else {
397
                die('Category does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
398
            }
399
            break;
400
                 
401
        case ($srcClass == 'Comment'):
402
            die('Comment does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
403
            break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
404
                    
405
        case ($srcClass == 'User'):
406
            if ($navigationPropName == 'Posts') {
407
                $query = "SELECT * FROM `wp_posts` WHERE"
408
                       ." wp_posts.post_type = 'post'"
409
                       ." AND wp_posts.post_status = 'publish'"
410
                       ." AND wp_posts.post_author = $sourceEntityInstance->UserID";
411
                if ($filter !== null) {
412
                    $query .= " AND $filter";
413
                }
414
                $stmt = mysql_query($query);
415
                if ( $stmt === false) {
416
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
417
                }
418
                            
419
                $result = $this->_serializePosts($stmt);
420 View Code Duplication
            } elseif ($navigationPropName == 'Comments') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
421
                $query = "SELECT * FROM `wp_comments`"
422
                     ." WHERE comment_approved = 1" 
423
                     ." AND wp_comments.user_id = $sourceEntityInstance->UserID";
424
                if ($filter !== null) {
425
                    $query .= " AND $filter";
426
                }
427
                $stmt = mysql_query($query);
428
                if ( $stmt === false) {            
429
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
430
                }
431
                        
432
                $result = $this->_serializeComments($stmt);
433
            } else {
434
                die('User does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
435
            }
436
            break;
437
        }
438
        
439
        mysql_free_result($stmt);
0 ignored issues
show
Bug introduced by
The variable $stmt 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...
440
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $result; (array) is incompatible with the return type declared by the interface POData\Providers\Query\I...::getRelatedResourceSet of type POData\Providers\Query\QueryResult.

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...
441
    }
442
    
443
    /**
444
     * Gets a related entity instance from an entity set identifed by a key
445
     * 
446
     * @param ResourceSet      $sourceResourceSet    The entity set related to
447
     *                                               the entity to be fetched.
448
     * @param object           $sourceEntityInstance The related entity instance.
449
     * @param ResourceSet      $targetResourceSet    The entity set from which
450
     *                                               entity needs to be fetched.
451
     * @param ResourceProperty $targetProperty       The metadata of the target 
452
     *                                               property.
453
     * @param KeyDescriptor    $keyDescriptor        The key to identify the entity 
454
     *                                               to be fetched.
455
     * 
456
     * @return object|null Returns entity instance if found else null
457
     */
458
    public function  getResourceFromRelatedResourceSet(ResourceSet $sourceResourceSet, 
459
        $sourceEntityInstance, 
460
        ResourceSet $targetResourceSet,
461
        ResourceProperty $targetProperty,
462
        KeyDescriptor $keyDescriptor
463
    ) {
464
        $result = array();
465
        $srcClass = get_class($sourceEntityInstance);
466
        $navigationPropName = $targetProperty->getName();
467
        
468
        $keys = array();
469
        $namedKeyValues = $keyDescriptor->getValidatedNamedValues();
470
        foreach ($namedKeyValues as $key => $value) {
471
            $keys[] = "$key = '$value[0]' ";
472
        }
473
        $conditionStr = implode(' AND ', $keys);
0 ignored issues
show
Unused Code introduced by
$conditionStr is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
474
        
475
        switch (true) {
476
        case ($srcClass == 'Post'):
477
            if ($navigationPropName == 'Tags') {
478
                $query = "SELECT t.*, tt.description"
479
                       ." FROM wp_terms AS t"
480
                       ." INNER JOIN wp_term_taxonomy AS tt"
481
                       ." ON tt.term_id = t.term_id"
482
                       ." INNER JOIN wp_term_relationships AS tr"
483
                       ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
484
                       ." WHERE tt.taxonomy IN ('post_tag')"
485
                       ." AND tr.object_id IN ($sourceEntityInstance->PostID)"
486
                       ." AND tt.term_id = ".$namedKeyValues['TagID'][0];
487
                $stmt = mysql_query($query);
488
                $result = $this->_serializeTags($stmt);
489
            } elseif ($navigationPropName == 'Categories') {
490
                $query = "SELECT t.*, tt.description"
491
                       ." FROM wp_terms AS t"
492
                       ." INNER JOIN wp_term_taxonomy AS tt"
493
                       ." ON tt.term_id = t.term_id"
494
                       ." INNER JOIN wp_term_relationships AS tr"
495
                       ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
496
                       ." WHERE tt.taxonomy IN ('category')"
497
                       ." AND tr.object_id IN ($sourceEntityInstance->PostID)"
498
                       ." AND tt.term_id = ".$namedKeyValues['CategoryID'][0];
499
                $stmt = mysql_query($query);
500
                $result = $this->_serializeCategories($stmt);
501 View Code Duplication
            } else if ($navigationPropName == 'Comments') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
502
                $query = "SELECT * FROM `wp_comments`"
503
                       ." WHERE comment_approved = 1" 
504
                       ." AND comment_post_ID = $sourceEntityInstance->PostID"
505
                       ." AND comment_ID = ".$namedKeyValues['CommentID'][0];
506
                $stmt = mysql_query($query);
507
                $result = $this->_serializeComments($stmt);
508
            } else {
509
                die('Post does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
510
            }
511
            break;
512
513 View Code Duplication
        case ($srcClass == 'Tag'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
514
            if ($navigationPropName == 'Posts') {
515
                $query = "SELECT p . *" 
516
                         ." FROM wp_posts AS p"
517
                         ." INNER JOIN wp_term_relationships AS tr"
518
                         ." ON p.ID = tr.object_id"
519
                         ." INNER JOIN wp_term_taxonomy AS tt"
520
                         ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
521
                         ." WHERE tt.term_id = $sourceEntityInstance->TagID"
522
                         ." AND p.post_type = 'post'"
523
                         ." AND p.post_status = 'publish'"
524
                         ." AND p.ID = ".$namedKeyValues['PostID'][0];
525
                $stmt = mysql_query($query);
526
                $result = $this->_serializePosts($stmt);
527
            } else {
528
                die('Tag does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
529
            }
530
            break;
531
                    
532 View Code Duplication
        case ($srcClass == 'Category'):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
533
            if ($navigationPropName == 'Posts') {
534
                $query = "SELECT p . *" 
535
                         ." FROM wp_posts AS p"
536
                         ." INNER JOIN wp_term_relationships AS tr"
537
                         ." ON p.ID = tr.object_id"
538
                         ." INNER JOIN wp_term_taxonomy AS tt"
539
                         ." ON tr.term_taxonomy_id = tt.term_taxonomy_id"
540
                         ." WHERE tt.term_id = $sourceEntityInstance->CategoryID"
541
                         ." AND p.post_type = 'post'"
542
                         ." AND p.post_status = 'publish'"
543
                         ." AND p.ID = ".$namedKeyValues['PostID'][0];
544
                $stmt = mysql_query($query);
545
                $result = $this->_serializePosts($stmt);
546
            } else {
547
                die('Category does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
548
            }
549
            break;
550
                 
551
        case ($srcClass == 'Comment'):
552
            die('Comment does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
553
            break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
554
                    
555
        case ($srcClass == 'User'):
556
            if ($navigationPropName == 'Posts') {
557
                 $query = "SELECT * FROM `wp_posts` WHERE"
558
                        ." wp_posts.post_type = 'post'"
559
                        ." AND wp_posts.post_status = 'publish'"
560
                        ." AND wp_posts.post_author = $sourceEntityInstance->UserID"
561
                        ." AND wp_posts.ID = ".$namedKeyValues['PostID'][0];
562
                 $stmt = mysql_query($query);
563
                 $result = $this->_serializePosts($stmt);
564 View Code Duplication
            } elseif ($navigationPropName == 'Comments') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
565
                 $query = "SELECT * FROM `wp_comments`"
566
                      ." WHERE comment_approved = 1" 
567
                      ." AND wp_comments.user_id = $sourceEntityInstance->UserID"
568
                      ." AND wp_comments.comment_ID = ".$namedKeyValues['CommentID'][0];
569
                 $stmt = mysql_query($query);
570
                 $result = $this->_serializeComments($stmt);
571
            } else {
572
                 die('User does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getResourceFromRelatedResourceSet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
573
            }
574
            break;
575
        }
576
        
577
        mysql_free_result($stmt);
0 ignored issues
show
Bug introduced by
The variable $stmt 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...
578
        return empty($result) ? null : $result[0];
579
    }
580
    /**
581
     * Get related resource for a resource
582
     * 
583
     * @param ResourceSet      $sourceResourceSet    The source resource set
584
     * @param mixed            $sourceEntityInstance The source resource
585
     * @param ResourceSet      $targetResourceSet    The resource set of 
586
     *                                               the navigation property
587
     * @param ResourceProperty $targetProperty       The navigation property to be 
588
     *                                               retrieved
589
     * 
590
     * @return object|null The related resource if exists else null
591
     */
592
    public function getRelatedResourceReference(ResourceSet $sourceResourceSet, 
593
        $sourceEntityInstance, 
594
        ResourceSet $targetResourceSet,
595
        ResourceProperty $targetProperty
596
    ) {
597
        $result = null;
598
        $srcClass = get_class($sourceEntityInstance);
599
        $navigationPropName = $targetProperty->getName();
600
        
601
        switch (true) {
602
        case ($srcClass == 'Post'):
603
            if ($navigationPropName == 'User') {
604
                $query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->Author";
605
                $stmt = mysql_query($query);
0 ignored issues
show
Unused Code introduced by
$stmt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
606
                $stmt = mysql_query($query);
607
                $data = mysql_fetch_assoc($stmt);
608
                $result = $this->_serializeUser($data);
609
                if ( $stmt === false) {            
610
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceReference() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
611
                }
612
                        
613
                if (!mysql_num_rows($stmt)) {
614
                    $result =  null;
615
                }
616
            } else {
617
                die('Post does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceReference() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
618
            }
619
            break;
620
621
        case ($srcClass == 'Comment'):
622
            if ($navigationPropName == 'User') {
623
                $query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->UserID";
624
                $stmt = mysql_query($query);
625
                if ( $stmt === false) {
626
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceReference() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
627
                }
628
                        
629
                if (!mysql_num_rows($stmt)) {
630
                    $result =  null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
631
                }
632
                        
633
                $data = mysql_fetch_assoc($stmt);
634
                $result = $this->_serializeUser($data);
635
                      
636
            } elseif ($navigationPropName == 'Post') {
637
                $query = "SELECT * FROM `wp_posts` WHERE"
638
                       ." wp_posts.post_type = 'post'"
639
                       ." AND wp_posts.post_status = 'publish'"
640
                       ." AND wp_posts.ID = $sourceEntityInstance->PostID";
641
                $stmt = mysql_query($query);
642
                if ( $stmt === false) {            
643
                    die(mysql_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceReference() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
644
                }
645
                        
646
                if (!mysql_num_rows($stmt)) {
647
                    $result =  null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
648
                }
649
                        
650
                $data = mysql_fetch_assoc($stmt);
651
                $result = $this->_serializePost($data);
652
            } else {
653
                die('Comment does not have navigation porperty with name: ' . $navigationPropName);
0 ignored issues
show
Coding Style Compatibility introduced by
The method getRelatedResourceReference() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
654
            }
655
            break;
656
        }
657
        
658
        mysql_free_result($stmt);
0 ignored issues
show
Bug introduced by
The variable $stmt 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...
659
        return $result;
660
    }
661
    
662
    /**
663
     * Serialize the mysql result array into Post objects
664
     * 
665
     * @param array(array) $result result of the mysql query
0 ignored issues
show
Documentation introduced by
The doc-type array(array) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
666
     * 
667
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
668
     */
669
    private function _serializePosts($result)
670
    {
671
        $posts = array();
672
        while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) {
673
             $posts[] = $this->_serializePost($record);
674
        }
675
676
        return $posts;
677
    }
678
679
    /**
680
     * Serialize the mysql row into Post object
681
     * 
682
     * @param array $record each post row
683
     * 
684
     * @return object
685
     */
686
    private function _serializePost($record)
687
    {
688
        $post = new Post();
689
        $post->PostID = $record['ID'];
690
        $post->Author = $record['post_author'];
691
        
692 View Code Duplication
        if (!is_null($record['post_date'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
693
            $dateTime = new DateTime($record['post_date']);
694
            $post->Date = $dateTime->format('Y-m-d\TH:i:s');
695
        } else {
696
            $post->Date = null;
697
        }
698
        
699 View Code Duplication
        if (!is_null($record['post_date_gmt'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
700
            $dateTime = new DateTime($record['post_date_gmt']);
701
            $post->DateGmt = $dateTime->format('Y-m-d\TH:i:s');
702
        } else {
703
            $post->DateGmt = null;
704
        }
705
        
706
        $post->Content = $record['post_content'];
707
        $post->Title = $record['post_title'];
708
        $post->Excerpt = $record['post_excerpt'];
709
        $post->Status = $record['post_status'];
710
        $post->CommentStatus = $record['comment_status'];
711
        $post->PingStatus = $record['ping_status'];
712
        $post->Password = $record['post_password'];
713
        $post->Name = $record['post_name'];
714
        $post->ToPing = $record['to_ping'];
715
        $post->Pinged = $record['pinged'];
716
        
717 View Code Duplication
        if (!is_null($record['post_modified'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
718
            $dateTime = new DateTime($record['post_modified']);
719
            $post->Modified = $dateTime->format('Y-m-d\TH:i:s');
720
        } else {
721
            $post->Modified = null;
722
        }
723
        
724 View Code Duplication
        if (!is_null($record['post_modified_gmt'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
725
            $dateTime = new DateTime($record['post_modified_gmt']);
726
            $post->ModifiedGmt = $dateTime->format('Y-m-d\TH:i:s');
727
        } else {
728
            $post->ModifiedGmt = null;
729
        }
730
        
731
        $post->ContentFiltered = $record['post_content_filtered'];
732
        $post->ParentID = $record['post_parent'];
733
        $post->Guid = $record['guid'];
734
        $post->MenuOrder = $record['menu_order'];
735
        $post->Type = $record['post_type'];
736
        $post->MimeType = $record['post_mime_type'];
737
        $post->CommentCount = $record['comment_count'];
738
        return $post;
739
    }
740
    
741
    /**
742
     * Serialize the mysql result array into Tag objects
743
     * 
744
     * @param array(array) $result result of the mysql query
0 ignored issues
show
Documentation introduced by
The doc-type array(array) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
745
     * 
746
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
747
     */
748 View Code Duplication
    private function _serializeTags($result)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
749
    {
750
        $tags = array();
751
        while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) {         
752
             $tags[] = $this->_serializeTag($record);
753
        }
754
755
        return $tags;
756
    }
757
758
    /**
759
     * Serialize the mysql row into Tag object
760
     * 
761
     * @param array $record each tag row
762
     * 
763
     * @return object
764
     */
765
    private function _serializeTag($record)
766
    {
767
        $tag = new Tag();
768
        $tag->TagID = $record['term_id'];
769
        $tag->Name = $record['name'];
770
        $tag->Slug = $record['slug'];
771
        $tag->Description = $record['description'];
772
        return $tag;
773
    }
774
    
775
    /**
776
     * Serialize the mysql result array into Category objects
777
     * 
778
     * @param array(array) $result result of the mysql query
0 ignored issues
show
Documentation introduced by
The doc-type array(array) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
779
     * 
780
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
781
     */
782 View Code Duplication
    private function _serializeCategories($result)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
783
    {
784
        $cats = array();
785
        while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) {         
786
             $cats[] = $this->_serializeCategory($record);
787
        }
788
789
        return $cats;
790
    }
791
792
    /**
793
     * Serialize the mysql row into Category object
794
     * 
795
     * @param array $record each category row
796
     * 
797
     * @return object
798
     */
799
    private function _serializeCategory($record)
800
    {
801
        $cat = new Category();
802
        $cat->CategoryID = $record['term_id'];
803
        $cat->Name = $record['name'];
804
        $cat->Slug = $record['slug'];
805
        $cat->Description = $record['description'];
806
        return $cat;
807
    }
808
    
809
    /**
810
     * Serialize the mysql result array into Comment objects
811
     * 
812
     * @param array(array) $result mysql query result
0 ignored issues
show
Documentation introduced by
The doc-type array(array) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
813
     * 
814
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
815
     */
816
    private function _serializeComments($result)
817
    {
818
        $comments = array();
819
        while ( $record = mysql_fetch_array($result, MYSQL_ASSOC)) {         
820
             $comments[] = $this->_serializeComment($record);
821
        }
822
823
        return $comments;
824
    }
825
826
    /**
827
     * Serialize the mysql row into Comment object
828
     * 
829
     * @param array $record each comment row
830
     * 
831
     * @return object
832
     */
833
    private function _serializeComment($record)
834
    {
835
        $comment = new Comment();
836
        $comment->CommentID = $record['comment_ID'];
837
        $comment->PostID = $record['comment_post_ID'];
838
        $comment->Author = $record['comment_author'];
839
        $comment->AuthorEmail = $record['comment_author_email'];
840
        $comment->AuthorUrl = $record['comment_author_url'];
841
        $comment->AuthorIp = $record['comment_author_IP'];
842
        
843 View Code Duplication
        if (!is_null($record['comment_date'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
844
            $dateTime = new DateTime($record['comment_date']);
845
            $comment->Date = $dateTime->format('Y-m-d\TH:i:s');
846
        } else {
847
            $comment->Date = null;
848
        }
849
        
850 View Code Duplication
        if (!is_null($record['comment_date_gmt'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
851
            $dateTime = new DateTime($record['comment_date_gmt']);
852
            $comment->DateGmt = $dateTime->format('Y-m-d\TH:i:s');
853
        } else {
854
            $comment->DateGmt = null;
855
        }
856
        
857
        $comment->Content = $record['comment_content'];
858
        $comment->Karma = $record['comment_karma'];
859
        $comment->Approved = $record['comment_approved'];
860
        $comment->Agent = $record['comment_agent'];
861
        $comment->Type = $record['comment_type'];
862
        $comment->ParentID = $record['comment_parent'];
863
        $comment->UserID = $record['user_id'];
864
        return $comment;
865
    }
866
    
867
    /**
868
     * Serialize the mysql result array into User objects
869
     * 
870
     * @param array(array) $result result of the mysql query
0 ignored issues
show
Documentation introduced by
The doc-type array(array) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
871
     * 
872
     * @return array(Object)
0 ignored issues
show
Documentation introduced by
The doc-type array(Object) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
873
     */
874
    private function _serializeUsers($result)
875
    {
876
        $users = array();
877
        while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) {         
878
             $users[] = $this->_serializeUser($record);
879
        }
880
881
        return $users;
882
    }
883
884
    /**
885
     * Serialize the mysql row into User object
886
     * 
887
     * @param array $record each user row
888
     * 
889
     * @return object
890
     */
891
    private function _serializeUser($record)
892
    {
893
        $user = new User();
894
        $user->UserID = $record['ID'];
895
        $user->Login = $record['user_login'];
896
        $user->Nicename = $record['user_nicename'];
897
        $user->Email = $record['user_email'];
898
        $user->Url = $record['user_url'];
899
        
900 View Code Duplication
        if (!is_null($record['user_registered'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
901
            $dateTime = new DateTime($record['user_registered']);
902
            $user->Registered = $dateTime->format('Y-m-d\TH:i:s');
903
        } else {
904
            $user->Registered = null;
905
        }
906
        
907
        $user->Status = $record['user_status'];
908
        $user->DisplayName = $record['display_name'];
909
        return $user;
910
    }
911
    
912
    
913
}
914