Skip to content

Commit

Permalink
Merge branch 'master' of github.com:stevenmaguire/trello-php
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Oct 27, 2022
2 parents 3814d2d + bebb33e commit afea1b4
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 55 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.cache
@@ -0,0 +1 @@
{"php":"8.1.11","version":"3.12.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Client.php":340015301,"src\/Traits\/AuthorizationTrait.php":1430451918,"src\/Traits\/ConfigurationTrait.php":1693681187,"src\/Traits\/ApiMethodsTrait.php":2661531181,"src\/Traits\/SearchTrait.php":703485025,"src\/Traits\/BatchTrait.php":3454705718,"src\/Exceptions\/Exception.php":1782820415,"src\/Authorization.php":1221993004,"src\/Configuration.php":1688230881,"src\/Http.php":3367408034,"tests\/ConfigurationTest.php":2540549043,"tests\/ClientTest.php":1856524567,"tests\/ApiTestTrait.php":624008844,"tests\/BuilderTest.php":2838921426,"tests\/AuthorizationTest.php":2411110082}}
5 changes: 3 additions & 2 deletions src/Authorization.php
@@ -1,6 +1,7 @@
<?php namespace Stevenmaguire\Services\Trello;
<?php

namespace Stevenmaguire\Services\Trello;

use League\OAuth1\Client\Credentials\CredentialsInterface;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use League\OAuth1\Client\Server\Trello as OAuthServer;

Expand Down
18 changes: 10 additions & 8 deletions src/Client.php
@@ -1,14 +1,16 @@
<?php namespace Stevenmaguire\Services\Trello;
<?php

namespace Stevenmaguire\Services\Trello;

use GuzzleHttp\ClientInterface as HttpClient;

class Client
{
use Traits\ApiMethodsTrait,
Traits\AuthorizationTrait,
Traits\BatchTrait,
Traits\ConfigurationTrait,
Traits\SearchTrait;
use Traits\ApiMethodsTrait;
use Traits\AuthorizationTrait;
use Traits\BatchTrait;
use Traits\ConfigurationTrait;
use Traits\SearchTrait;

/**
* Default client options
Expand Down Expand Up @@ -39,7 +41,7 @@ public function __construct($options = [])
{
Configuration::setMany($options, static::$defaultOptions);

$this->http = new Http;
$this->http = new Http();
}

/**
Expand All @@ -49,7 +51,7 @@ public function __construct($options = [])
*/
public function getAuthorization()
{
return new Authorization;
return new Authorization();
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Configuration.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello;
<?php

namespace Stevenmaguire\Services\Trello;

class Configuration
{
Expand All @@ -14,7 +16,7 @@ class Configuration
*
* @param string $key
*
* @return boolean
* @return bool
*/
public static function has($key)
{
Expand All @@ -32,7 +34,7 @@ public static function has($key)
*/
public static function get($key = null, $default = null)
{
if (!empty($key)) {
if (! empty($key)) {
return isset(static::$settings[$key]) ? static::$settings[$key] : $default;
}

Expand All @@ -50,7 +52,7 @@ public static function get($key = null, $default = null)
public static function parseDefaultOptions($options = [], $defaults = [])
{
array_walk($defaults, function ($value, $key) use (&$options) {
if (!isset($options[$key])) {
if (! isset($options[$key])) {
$options[$key] = $value;
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/Exception.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Exceptions;
<?php

namespace Stevenmaguire\Services\Trello\Exceptions;

use Exception as BaseException;

Expand Down
18 changes: 10 additions & 8 deletions src/Http.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello;
<?php

namespace Stevenmaguire\Services\Trello;

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\ClientInterface as HttpClientInterface;
Expand All @@ -9,10 +11,10 @@

class Http
{
const HTTP_DELETE = 'DELETE';
const HTTP_GET = 'GET';
const HTTP_POST = 'POST';
const HTTP_PUT = 'PUT';
public const HTTP_DELETE = 'DELETE';
public const HTTP_GET = 'GET';
public const HTTP_POST = 'POST';
public const HTTP_PUT = 'PUT';

/**
* Multipart resources to include in next request.
Expand All @@ -33,7 +35,7 @@ class Http
*/
public function __construct()
{
$this->httpClient = new HttpClient;
$this->httpClient = new HttpClient();
}

/**
Expand Down Expand Up @@ -176,10 +178,10 @@ private function getRequestExceptionParts(RequestException $requestException)
protected function getRequestOptions()
{
$options = [
'proxy' => Configuration::get('proxy')
'proxy' => Configuration::get('proxy'),
];

if (!empty(array_filter($this->multipartResources))) {
if (! empty(array_filter($this->multipartResources))) {
$options['multipart'] = $this->multipartResources;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Traits/ApiMethodsTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Traits;
<?php

namespace Stevenmaguire\Services\Trello\Traits;

use BadMethodCallException;

Expand Down Expand Up @@ -309,13 +311,13 @@ trait ApiMethodsTrait
'deleteOrganizationPrefAssociatedDomain' => ['delete', 'organizations/%s/prefs/associatedDomain'],
'updateOrganizationPrefAssociatedDomain' => ['put', 'organizations/%s/prefs/associatedDomain'],
'updateOrganizationPrefBoardVisibilityRestrictOrg' => [
'put', 'organizations/%s/prefs/boardVisibilityRestrict/org'
'put', 'organizations/%s/prefs/boardVisibilityRestrict/org',
],
'updateOrganizationPrefBoardVisibilityRestrictPrivate' => [
'put', 'organizations/%s/prefs/boardVisibilityRestrict/private'
'put', 'organizations/%s/prefs/boardVisibilityRestrict/private',
],
'updateOrganizationPrefBoardVisibilityRestrictPublic' => [
'put', 'organizations/%s/prefs/boardVisibilityRestrict/public'
'put', 'organizations/%s/prefs/boardVisibilityRestrict/public',
],
'updateOrganizationPrefExternalMembersDisabled' => ['put', 'organizations/%s/prefs/externalMembersDisabled'],
'updateOrganizationPrefGoogleAppsVersion' => ['put', 'organizations/%s/prefs/googleAppsVersion'],
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/AuthorizationTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Traits;
<?php

namespace Stevenmaguire\Services\Trello\Traits;

use League\OAuth1\Client\Credentials\TemporaryCredentials;

Expand Down
5 changes: 3 additions & 2 deletions src/Traits/BatchTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Traits;
<?php

namespace Stevenmaguire\Services\Trello\Traits;

use Stevenmaguire\Services\Trello\Exceptions\Exception;

Expand Down Expand Up @@ -33,7 +35,6 @@ public function addBatchUrl($url)
return $this;
}


/**
* Adds multiple urls to batch collection.
*
Expand Down
8 changes: 5 additions & 3 deletions src/Traits/ConfigurationTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Traits;
<?php

namespace Stevenmaguire\Services\Trello\Traits;

use Stevenmaguire\Services\Trello\Configuration;

Expand All @@ -7,7 +9,7 @@ trait ConfigurationTrait
/**
* Confirms that a given key exists in configuration settings.
*
* @return boolean
* @return bool
*/
public function hasConfig()
{
Expand All @@ -34,7 +36,7 @@ public function addConfig()
{
$params = func_get_args();

if (!empty($params)) {
if (! empty($params)) {
if (is_array($params[0])) {
forward_static_call_array([Configuration::class, 'setMany'], $params);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/SearchTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Traits;
<?php

namespace Stevenmaguire\Services\Trello\Traits;

trait SearchTrait
{
Expand Down
8 changes: 5 additions & 3 deletions tests/ApiTestTrait.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Tests;
<?php

namespace Stevenmaguire\Services\Trello\Tests;

use Stevenmaguire\Services\Trello\Exceptions\Exception;

Expand Down Expand Up @@ -298,7 +300,7 @@ public function testGetBatchWithString()

public function testAddBatchUrlsAndGetBatch()
{
$urlCount = rand(2,10);
$urlCount = rand(2, 10);
$urls = [];
for ($i = 0; $i < $urlCount; $i++) {
$request = $this->client->getHttp()->getRequest('get', '/', [], false);
Expand All @@ -317,7 +319,7 @@ public function testAddBatchUrlsAndGetBatch()

public function testGetBatchRetainsUrlsWithFailure()
{
$urlCount = rand(2,10);
$urlCount = rand(2, 10);
$urls = [];
for ($i = 0; $i < $urlCount; $i++) {
$request = $this->client->getHttp()->getRequest('get', '/', [], false);
Expand Down
20 changes: 11 additions & 9 deletions tests/AuthorizationTest.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Tests;
<?php

namespace Stevenmaguire\Services\Trello\Tests;

use League\OAuth1\Client\Credentials\TemporaryCredentials;
use League\OAuth1\Client\Credentials\TokenCredentials;
Expand All @@ -22,7 +24,7 @@ public function setUp()

Configuration::setMany($settings);

$this->auth = new Authorization;
$this->auth = new Authorization();
$this->client = m::mock(Client::class)->makePartial();
}

Expand All @@ -33,7 +35,7 @@ protected function getClientMock($options = [])

public function testGetAuthorizationUrlWithNoCredentials()
{
$tempCredentials = new TemporaryCredentials;
$tempCredentials = new TemporaryCredentials();
$mock = $this->getClientMock();
$mock->shouldReceive('getTemporaryCredentials')->andReturn($tempCredentials);
$mock->shouldReceive('getAuthorizationUrl')->with($tempCredentials);
Expand All @@ -45,7 +47,7 @@ public function testGetAuthorizationUrlWithNoCredentials()

public function testGetAuthorizationUrlWithCredentials()
{
$tempCredentials = new TemporaryCredentials;
$tempCredentials = new TemporaryCredentials();
$mock = $this->getClientMock();
$mock->shouldReceive('getAuthorizationUrl')->with($tempCredentials);
$this->auth->setClient($mock);
Expand All @@ -57,12 +59,12 @@ public function testGetAuthorizationUrlWithCredentials()
public function testGetTokenWithNoCredentials()
{
$sessionKey = Authorization::class.':temporary_credentials';
$tempCredentials = new TemporaryCredentials;
$tempCredentials = new TemporaryCredentials();
$_SESSION[$sessionKey] = serialize($tempCredentials);
session_write_close();
$oauthToken = uniqid();
$oauthVerifier = uniqid();
$tokenCredentials = new TokenCredentials;
$tokenCredentials = new TokenCredentials();
$mock = $this->getClientMock();
$mock->shouldReceive('getTokenCredentials')->with(m::on(function ($creds) {
return is_a($creds, TemporaryCredentials::class);
Expand All @@ -77,10 +79,10 @@ public function testGetTokenWithNoCredentials()

public function testGetTokenWithCredentials()
{
$tempCredentials = new TemporaryCredentials;
$tempCredentials = new TemporaryCredentials();
$oauthToken = uniqid();
$oauthVerifier = uniqid();
$tokenCredentials = new TokenCredentials;
$tokenCredentials = new TokenCredentials();
$mock = $this->getClientMock();
$mock->shouldReceive('getTokenCredentials')->with(m::on(function ($creds) use ($tempCredentials) {
return $tempCredentials === $creds;
Expand All @@ -95,7 +97,7 @@ public function testGetTokenWithCredentials()

public function testGetTemporaryCredentials()
{
$tempCredentials = new TemporaryCredentials;
$tempCredentials = new TemporaryCredentials();
$mock = $this->getClientMock();
$mock->shouldReceive('getTemporaryCredentials')->andReturn($tempCredentials);
$this->auth->setClient($mock);
Expand Down
8 changes: 5 additions & 3 deletions tests/BuilderTest.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Tests;
<?php

namespace Stevenmaguire\Services\Trello\Tests;

use Stevenmaguire\Services\Trello\Client;

Expand Down Expand Up @@ -39,7 +41,7 @@ protected function getPathFromMethod($method)
preg_match_all('/((?:^|[A-Z])[a-z]+)/', $method, $matches);
$parts = $matches[0];
array_shift($parts);
if (!empty($parts)) {
if (! empty($parts)) {
$parts[0] = $parts[0].'s';

$parts = array_map('strtolower', $parts);
Expand Down Expand Up @@ -74,7 +76,7 @@ public function testBuilder()
$details = '['."\n";

foreach ($ref->getMethods() as $method) {
if (!in_array($method->getName(), $dontWrite)) {
if (! in_array($method->getName(), $dontWrite)) {
$contents = [];
$contents['name'] = $method->getName();
$filename = $method->getFileName();
Expand Down
11 changes: 7 additions & 4 deletions tests/ClientTest.php
@@ -1,8 +1,10 @@
<?php namespace Stevenmaguire\Services\Trello\Tests;
<?php

namespace Stevenmaguire\Services\Trello\Tests;

use GuzzleHttp\ClientInterface as HttpClient;
use Mockery as m;
use GuzzleHttp\Exception\BadResponseException;
use Mockery as m;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -91,14 +93,15 @@ protected function prepareFor($method, $path, $query = "", $payload = [], $statu
return $request->getMethod() === strtoupper($method)
&& $uri->getScheme().'://'.$uri->getHost() === $domain
&& $uri->getPath() === $path
&& (!empty($query) ? (strpos($uri->getQuery(), $query) > -1) : true)
&& (! empty($query) ? (strpos($uri->getQuery(), $query) > -1) : true)
&& strpos($uri->getQuery(), $authorizedQuery) > -1;
});

$requestOptions = m::on(function ($options) use ($proxy) {
if ($proxy && (!isset($options['proxy']) || $options['proxy'] != $proxy)) {
if ($proxy && (! isset($options['proxy']) || $options['proxy'] != $proxy)) {
return false;
}

return is_array($options);
});

Expand Down
6 changes: 4 additions & 2 deletions tests/ConfigurationTest.php
@@ -1,4 +1,6 @@
<?php namespace Stevenmaguire\Services\Trello\Tests;
<?php

namespace Stevenmaguire\Services\Trello\Tests;

use Stevenmaguire\Services\Trello\Client;
use Stevenmaguire\Services\Trello\Configuration;
Expand All @@ -8,7 +10,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();
$this->client = new Client;
$this->client = new Client();
$config = new \ReflectionClass(Configuration::class);
$settings = $config->getProperty('settings');
$settings->setAccessible(true);
Expand Down

0 comments on commit afea1b4

Please sign in to comment.