Skip to content

Commit

Permalink
[TASK] Fix php code style
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Mar 11, 2024
1 parent 5b56a13 commit 18d84d9
Show file tree
Hide file tree
Showing 36 changed files with 114 additions and 107 deletions.
10 changes: 7 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.gitattributes export-ignore
.php_cs export-ignore
/tests export-ignore
/examples export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/phpunit.xml export-ignore
/.phpstorm.meta.php export-ignore
/rector.php export-ignore
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/tests/data/
/tests/build/
/vendor/
.env
.php_cs.cache
composer.lock
/.env
/.php-cs-fixer.cache
/composer.lock
54 changes: 54 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}

return (new \PhpCsFixer\Config())
->setFinder(
(new \PhpCsFixer\Finder())
->ignoreVCSIgnored(true)
->in([
__DIR__ . '/src/',
__DIR__ . '/tests/',
])
)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'no_leading_import_slash' => true,
'array_syntax' => ['syntax' => 'short'],
'cast_spaces' => ['space' => 'none'],
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'single'],
'dir_constant' => true,
'function_typehint_space' => true,
'lowercase_cast' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_statement' => true,
'no_leading_namespace_whitespace' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'whitespace_after_comma_in_array' => true,
]);
12 changes: 0 additions & 12 deletions .php_cs

This file was deleted.

4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"TeamWorkPm\\": "src/"
Expand All @@ -28,9 +27,6 @@
"tests/functions.php"
]
},
"config": {
"preferred-install": "dist"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.6-dev"
Expand Down
4 changes: 2 additions & 2 deletions src/Milestone.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function init()
'attributes' => [
'type' => 'integer',
],
],//format YYYYMMDD
], //format YYYYMMDD
'notify' => [
'required' => false,
'attributes' => [
Expand All @@ -35,7 +35,7 @@ protected function init()
],
],
'responsible_party_ids' => true,
# USE ONLY FOR UPDATE OR PUT METHOD
// USE ONLY FOR UPDATE OR PUT METHOD
'move_upcoming_milestones' => [
'sibling' => true,
'required' => false,
Expand Down
2 changes: 1 addition & 1 deletion src/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function update(array $data)

/**
* @param int $id
* @param null $project_id
* @param int|null $project_id
*
* @return bool
* @throws \TeamWorkPm\Exception
Expand Down
1 change: 0 additions & 1 deletion src/Portfolio/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ public function update(array $data)

return $this->rest->put("$this->action/$cardId/move", $data);
}

}
4 changes: 2 additions & 2 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected function init()
'status' => false,
'customFields' => [
'required' => false,
'type' => 'array'
]
'type' => 'array',
],
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Project/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ public function update(array $data)
$project_id = (int)(empty($data['project_id']) ? 0 : $data['project_id']);
$person_id = (int)(empty($data['person_id']) ? 0 : $data['person_id']);
if ($project_id <= 0) {
throw new Exception("Required field project_id");
throw new Exception('Required field project_id');
}
if ($person_id <= 0) {
throw new Exception("Required field person_id");
throw new Exception('Required field person_id');
}
return $this->rest->put("projects/$project_id/people/$person_id", $data);
}
Expand Down
10 changes: 4 additions & 6 deletions src/Request/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

namespace TeamWorkPm\Request;

use \stdClass;

class JSON extends Model
{
protected function parseParameters($parameters)
{
if (!empty($parameters) && is_array($parameters)) {
$object = new stdClass();
$object = new \stdClass();
$parent = $this->getParent();
$object->$parent = new stdClass();
$object->$parent = new \stdClass();
$parent = $object->$parent;

if ($this->actionInclude('/reorder')) {
foreach ($parameters as $id) {
$item = new stdClass();
$item = new \stdClass();
$item->id = $id;
$parent->{$this->parent}[] = $item;
}
Expand All @@ -38,7 +36,7 @@ protected function parseParameters($parameters)
}
}
}
if (null !== $value) {
if ($value !== null) {
if (is_string($value)) {
$value = mb_encode_numericentity(
$value,
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function getValue(&$field, &$options, array $parameters)
if (!is_array($options)) {
$options = ['required' => $options, 'attributes' => []];
}
$isNull = null === $value;
$isNull = $value === null;
if ($this->method === 'POST' && $options['required']) {
if ($isNull) {
throw new Exception('Required field ' . $field);
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function getValue(&$field, &$options, array $parameters)

protected function actionInclude($value)
{
return false !== strrpos($this->action, $value);
return strrpos($this->action, (string)$value) !== false;
}

protected function getParent()
Expand Down
4 changes: 2 additions & 2 deletions src/Request/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function parseParameters($parameters)
$element = $this->doc->createElement($field);
if (isset($options['attributes'])) {
foreach ($options['attributes'] as $name => $type) {
if (null !== $value) {
if ($value !== null) {
$element->setAttribute($name, $type);
if ($name == 'type') {
if ($type == 'array') {
Expand All @@ -48,7 +48,7 @@ protected function parseParameters($parameters)
}
}
}
if (null !== $value) {
if ($value !== null) {
if (is_bool($value)) {
$value = var_export($value, true);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Response/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace TeamWorkPm\Response;

use ArrayObject;
use stdClass;
use TeamWorkPm\Exception;
use TeamWorkPm\Helper\Str;

Expand Down Expand Up @@ -134,17 +132,17 @@ protected function getContent()
}

/**
* @param array|stdClass $source
* @param array|\stdClass $source
*
* @return ArrayObject
* @return \ArrayObject
*/
protected static function camelizeObject($source)
{
if (!is_object($source) && !is_array($source)) {
return $source;
}

$destination = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
$destination = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
foreach ($source as $key => $value) {
if (ctype_upper($key)) {
$key = strtolower($key);
Expand Down
9 changes: 2 additions & 7 deletions src/Response/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

namespace TeamWorkPm\Response;

use ArrayAccess;
use ArrayIterator;
use Countable;
use IteratorAggregate;

abstract class Model implements IteratorAggregate, Countable, ArrayAccess
abstract class Model implements \IteratorAggregate, \Countable, \ArrayAccess
{
protected $string = null;

Expand Down Expand Up @@ -56,7 +51,7 @@ public function getHeaders()

public function getIterator()
{
return new ArrayIterator($this->data);
return new \ArrayIterator($this->data);
}

public function count()
Expand Down
16 changes: 7 additions & 9 deletions src/Response/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace TeamWorkPm\Response;

use SimpleXMLElement;
use TeamWorkPm\Exception;
use \TeamWorkPm\Helper\Str;
use \stdClass;
use \SimpleXMLElement;
use \DOMDocument;
use TeamWorkPm\Helper\Str;

class XML extends Model
{
Expand Down Expand Up @@ -95,7 +93,7 @@ public function parse($data, array $headers)
*/
protected function getContent()
{
$dom = new DOMDocument('1.0');
$dom = new \DOMDocument('1.0');
$dom->loadXML($this->string);
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
Expand All @@ -106,15 +104,15 @@ protected function getContent()
/**
* Convierte un objecto SimpleXMLElement a stdClass
*
* @param SimpleXMLElement $source
* @param \SimpleXMLElement $source
* @param bool $isArray
* @return stdClass
* @return \stdClass
*/
private static function toStdClass(
SimpleXMLElement $source,
\SimpleXMLElement $source,
$isArray = false
) {
$destination = $isArray ? [] : new stdClass();
$destination = $isArray ? [] : new \stdClass();
foreach ($source as $key => $value) {
$key = Str::camel($key);
$attrs = $value->attributes();
Expand Down
2 changes: 1 addition & 1 deletion src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ public function addTagToResource($resource = '', $id = null)
{
return $this->rest->put("$resource/$id/$this->action");
}
}
}
2 changes: 1 addition & 1 deletion src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function init()
],
'responsible_party_id' => false,
'attachments' => false,
'pending_file_attachments' => false
'pending_file_attachments' => false,
];
$this->parent = 'todo-item';
$this->action = 'todo_items';
Expand Down
2 changes: 1 addition & 1 deletion tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ public function authenticate()
$this->fail($e->getMessage());
}
}
}
}
2 changes: 1 addition & 1 deletion tests/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public function getByProject()
$this->fail($e->getMessage());
}
}
}
}
2 changes: 1 addition & 1 deletion tests/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function insert($data)
$this->fail('An expected exception has not been raised.');
} catch (Exception $e) {
$this->assertEquals(
"Invalid value for field countrycode",
'Invalid value for field countrycode',
$e->getMessage()
);
}
Expand Down
Loading

0 comments on commit 18d84d9

Please sign in to comment.