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:
1 | <?php |
||
46 | class WSClient |
||
47 | { |
||
48 | private $session = null; |
||
49 | |||
50 | public $modules = null; |
||
51 | public $entities = null; |
||
52 | |||
53 | const USE_ACCESSKEY = 1; |
||
54 | const USE_PASSWORD = 2; |
||
55 | |||
56 | /** |
||
57 | * Class constructor |
||
58 | * @param string $vtigerUrl The URL of the remote WebServices server |
||
59 | * @param string $username User name |
||
60 | * @param string $secret Access key token (shown on user's profile page) or password, depends on $loginMode |
||
61 | * @param integer [$loginMode = self::USE_ACCESSKEY|USE_PASSWORD] Login mode, defaults to username + accessKey |
||
62 | * @param string [$wsBaseURL = 'webservice.php'] WebServices base URL appended to vTiger root URL |
||
63 | */ |
||
64 | public function __construct($vtigerUrl, $username, $secret, $loginMode = self::USE_ACCESSKEY, $wsBaseURL = 'webservice.php') |
||
92 | |||
93 | /** |
||
94 | * Invokes custom operation (defined in vtiger_ws_operation table) |
||
95 | * @access public |
||
96 | * @param string $operation Name of the webservice to invoke |
||
97 | * @param array [$params = null] Parameter values to operation |
||
98 | * @param string [$method = 'POST'] HTTP request method (GET, POST etc) |
||
99 | * @return array Result object |
||
100 | */ |
||
101 | public function invokeOperation($operation, array $params = null, $method = 'POST') |
||
113 | |||
114 | /** |
||
115 | * VTiger provides a simple query language for fetching data. |
||
116 | * This language is quite similar to select queries in SQL. |
||
117 | * There are limitations, the queries work on a single Module, |
||
118 | * embedded queries are not supported, and does not support joins. |
||
119 | * But this is still a powerful way of getting data from Vtiger. |
||
120 | * Query always limits its output to 100 records, |
||
121 | * Client application can use limit operator to get different records. |
||
122 | * @access public |
||
123 | * @param string $query SQL-like expression |
||
124 | * @return array Query results |
||
125 | */ |
||
126 | public function runQuery($query) |
||
135 | } |
||
136 | |||
154 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: