Function create
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function create(array $data = [])
{
$encoded = json_encode($data);
if (version_compare(phpversion(), '5.3.0', '>=')) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Missing class import via use statement (line '226', column '23'). Open
throw new Mollie_API_Exception("Error executing API call ({$object->error->type}): {$object->error->message}.");
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '116', column '48'). Open
$collection = $this->copy($result, new Mollie_API_Object_List());
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Remove error control operator '@' on line 221. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Missing class import via use statement (line '222', column '23'). Open
throw new Mollie_API_Exception("Unable to decode Mollie response: \"{$body}\".");
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '166', column '27'). Open
throw new Mollie_API_Exception('Error encoding parameters into JSON: "'.json_last_error().'".');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '170', column '27'). Open
throw new Mollie_API_Exception('Error encoding parameters into JSON.');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid assigning values to variables in if clauses and the like (line '221', column '15'). Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method create uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($encoded === false) {
throw new Mollie_API_Exception('Error encoding parameters into JSON.');
}
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The parameter $rest_resource is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $http_body is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $api_result is not named in camelCase. Open
private function copy($api_result, $object)
{
foreach ($api_result as $property => $value) {
if (property_exists(get_class($object), $property)) {
$object->$property = $value;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $rest_resource is not named in camelCase. Open
private function rest_read($rest_resource, $id)
{
$id = $id ? urlencode($id) : 'undefined';
$result = $this->performApiCall(self::REST_READ, "{$rest_resource}/{$id}");
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $rest_resource is not named in camelCase. Open
private function rest_create($rest_resource, $body)
{
$result = $this->performApiCall(self::REST_CREATE, $rest_resource, $body);
return $this->copy($result, $this->getResourceObject($rest_resource));
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $http_method is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Avoid variables with short names like $id. Configured minimum length is 3. Open
private function rest_read($rest_resource, $id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class Mollie_API_Resource_Base is not named in CamelCase. Open
abstract class Mollie_API_Resource_Base
{
const REST_CREATE = Mollie_API_Client::HTTP_POST;
const REST_UPDATE = Mollie_API_Client::HTTP_POST;
const REST_READ = Mollie_API_Client::HTTP_GET;
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The parameter $resource_id is not named in camelCase. Open
public function get($resource_id)
{
return $this->rest_read($this->getResourceName(), $resource_id);
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $api_method is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The variable $class_parts is not named in camelCase. Open
protected function getResourceName()
{
$class_parts = explode('_', get_class($this));
return mb_strtolower(end($class_parts));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $api_path is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $api_path is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $api_method is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $rest_resource is not named in camelCase. Open
private function rest_read($rest_resource, $id)
{
$id = $id ? urlencode($id) : 'undefined';
$result = $this->performApiCall(self::REST_READ, "{$rest_resource}/{$id}");
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $rest_resource is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $http_method is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $http_body is not named in camelCase. Open
protected function performApiCall($http_method, $api_method, $http_body = null)
{
$body = $this->api->performHttpCall($http_method, $api_method, $http_body);
if (!($object = @json_decode($body))) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $rest_resource is not named in camelCase. Open
private function rest_create($rest_resource, $body)
{
$result = $this->performApiCall(self::REST_CREATE, $rest_resource, $body);
return $this->copy($result, $this->getResourceObject($rest_resource));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $data_result is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $rest_resource is not named in camelCase. Open
private function rest_create($rest_resource, $body)
{
$result = $this->performApiCall(self::REST_CREATE, $rest_resource, $body);
return $this->copy($result, $this->getResourceObject($rest_resource));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $class_parts is not named in camelCase. Open
protected function getResourceName()
{
$class_parts = explode('_', get_class($this));
return mb_strtolower(end($class_parts));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $data_result is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $api_result is not named in camelCase. Open
private function copy($api_result, $object)
{
foreach ($api_result as $property => $value) {
if (property_exists(get_class($object), $property)) {
$object->$property = $value;
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $rest_resource is not named in camelCase. Open
private function rest_read($rest_resource, $id)
{
$id = $id ? urlencode($id) : 'undefined';
$result = $this->performApiCall(self::REST_READ, "{$rest_resource}/{$id}");
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $resource_id is not named in camelCase. Open
public function get($resource_id)
{
return $this->rest_read($this->getResourceName(), $resource_id);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The method rest_list is not named in camelCase. Open
private function rest_list($rest_resource, $offset = 0, $limit = self::DEFAULT_LIMIT)
{
$api_path = $rest_resource.'?'.http_build_query(['offset' => $offset, 'count' => $limit]);
$result = $this->performApiCall(self::REST_LIST, $api_path);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method rest_read is not named in camelCase. Open
private function rest_read($rest_resource, $id)
{
$id = $id ? urlencode($id) : 'undefined';
$result = $this->performApiCall(self::REST_READ, "{$rest_resource}/{$id}");
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method rest_create is not named in camelCase. Open
private function rest_create($rest_resource, $body)
{
$result = $this->performApiCall(self::REST_CREATE, $rest_resource, $body);
return $this->copy($result, $this->getResourceObject($rest_resource));
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}