From c3d6948457a57618c42913350a8f7f53882de73f Mon Sep 17 00:00:00 2001 From: Hassansin Date: Tue, 13 Jul 2021 13:33:14 +0600 Subject: [PATCH] GH actions setup (#85) --- .github/workflows/test.yml | 82 +++++++++++++++++++ .travis.yml | 36 -------- Makefile | 6 +- README.md | 4 +- composer.json | 3 +- src/Account.php | 7 +- src/Configuration.php | 2 - src/Customer.php | 11 +-- src/CustomerInvoices.php | 6 +- src/Customers.php | 7 +- src/DataSource.php | 7 +- src/Exceptions/ChartMogulException.php | 4 +- src/Exceptions/ForbiddenException.php | 1 - src/Exceptions/NotAllowedException.php | 1 - src/Exceptions/NotFoundException.php | 1 - src/Exceptions/ResourceInvalidException.php | 1 - src/Exceptions/SchemaInvalidException.php | 1 - src/Http/Client.php | 3 +- src/Http/ClientInterface.php | 1 - src/Http/Retry.php | 2 +- src/Import/Customer.php | 1 - src/Import/CustomerInvoices.php | 1 - src/Import/DataSource.php | 1 - src/Import/Invoice.php | 1 - src/Import/LineItems/OneTime.php | 1 - src/Import/LineItems/Subscription.php | 1 - src/Import/Plan.php | 1 - src/Import/Subscription.php | 1 - .../Transactions/AbstractTransaction.php | 1 - src/Import/Transactions/Payment.php | 1 - src/Import/Transactions/Refund.php | 1 - src/Invoice.php | 8 +- src/LineItems/AbstractLineItem.php | 1 - src/LineItems/OneTime.php | 1 - src/LineItems/Subscription.php | 1 - src/Metrics.php | 1 - src/Metrics/ARPAs.php | 6 +- src/Metrics/ARRs.php | 6 +- src/Metrics/ASPs.php | 6 +- src/Metrics/AbstractMetric.php | 2 - src/Metrics/Activities.php | 12 ++- src/Metrics/Activity.php | 2 - src/Metrics/AllKeyMetrics.php | 12 ++- src/Metrics/CustomerChurnRates.php | 6 +- src/Metrics/CustomerCounts.php | 6 +- src/Metrics/Customers/Activities.php | 12 ++- src/Metrics/Customers/Activity.php | 2 - src/Metrics/Customers/Subscription.php | 2 - src/Metrics/Customers/Subscriptions.php | 12 ++- src/Metrics/LTVs.php | 6 +- src/Metrics/MRRChurnRates.php | 6 +- src/Metrics/MRRs.php | 6 +- src/Ping.php | 4 +- src/Plan.php | 9 +- src/PlanGroup.php | 9 +- src/PlanGroups/Plan.php | 4 +- src/Resource/AbstractModel.php | 4 +- src/Resource/AbstractResource.php | 9 +- src/Resource/EntryTrait.php | 1 - src/Resource/SummaryTrait.php | 1 - src/Service/AllTrait.php | 3 +- src/Service/CreateTrait.php | 2 - src/Service/DestroyTrait.php | 3 +- src/Service/GetTrait.php | 2 +- src/Service/RequestService.php | 14 ++-- src/Service/ShowTrait.php | 2 +- src/Service/UpdateTrait.php | 1 - src/Subscription.php | 13 ++- src/Transactions/AbstractTransaction.php | 3 +- src/Transactions/Payment.php | 3 +- src/Transactions/Refund.php | 3 +- tests/Unit/Http/ClientTest.php | 2 +- 72 files changed, 189 insertions(+), 216 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..93358cc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,82 @@ +name: Run specs and generate Code Climate report +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['7.3', '7.4'] + phpunit-versions: ['latest'] + include: + - php-versions: '7.2' + phpunit-versions: '8.5.13' + - php-versions: '7.1' + phpunit-versions: '7.5.20' + steps: + - uses: actions/checkout@v2 + - name: Setup PHP ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: phpunit:${{ matrix.phpunit-versions }} + coverage: xdebug + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install dependencies + run: composer update --no-interaction --no-progress --prefer-dist + - name: Set ENV for codeclimate (pull_request) + run: | + git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF + echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV + echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV + if: github.event_name == 'pull_request' + - name: Set ENV for codeclimate (push) + run: | + echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV + if: github.event_name == 'push' + - name: Install Code Climate test report + run: | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + - name: Run tests + run: phpunit --coverage-text --coverage-clover ./build/logs/clover.xml + - name: Send Report to Code Climate + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + if: ${{ matrix.php-versions == '7.4' && success() }} + run: ./cc-test-reporter after-build + coding-guidelines: + name: "Coding Guidelines" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: cs2pr, php-cs-fixer + - name: "Run php-cs-fixer" + run: php-cs-fixer fix --dry-run src + static-analysis: + name: "Static Analysis" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: phpstan, cs2pr + - name: Install dependencies + run: composer update --no-interaction --no-progress --prefer-dist + - name: "Run phpstan" + run: phpstan analyse --error-format=checkstyle -l 4 src | cs2pr diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1d9f28b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -os: linux -dist: bionic - -language: php - -php: - - '7.1' - - '7.2' - - '7.3' - - '7.4' - - nightly - -branches: - only: - - main - - 1.x - -before_script: - - | - if [[ "$TRAVIS_PHP_VERSION" == 'nightly' ]]; then - #ignore php version check on nightly build - composer install --ignore-platform-reqs - else - composer install - fi - - if [[ "$TRAVIS_PHP_VERSION" == '7.1' ]]; then composer require phpunit/phpunit:^7; fi - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build - -script: - - if [[ "$TRAVIS_PHP_VERSION" == '7.1' ]]; then PHPUNIT=vendor/bin/phpunit; else PHPUNIT=phpunit; fi - - $PHPUNIT --coverage-text --coverage-clover ./build/logs/clover.xml - -after_script: - - ./cc-test-reporter after-build -t clover --exit-code $TRAVIS_TEST_RESULT diff --git a/Makefile b/Makefile index 62558ae..4a46baf 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ build: @docker build --build-arg VERSION=7.2 --tag=chartmogulphp72 . @docker build --build-arg VERSION=7.3 --tag=chartmogulphp73 . composer: - @$(RUNNER) "composer $(filter-out $@,$(MAKECMDGOALS))" + $(RUNNER) "composer $(filter-out $@,$(MAKECMDGOALS))" dependencies: make -s composer update -- --prefer-dist test: @@ -16,9 +16,5 @@ phpunit: $(RUNNER) "phpunit $(filter-out $@,$(MAKECMDGOALS))" php: $(RUNNER) "php $(filter-out $@,$(MAKECMDGOALS))" -cs: - $(RUNNER) "./vendor/bin/phpcs --standard=PSR2 src/" -cbf: - $(RUNNER) "./vendor/bin/phpcbf --standard=PSR2 src/" %: @: diff --git a/README.md b/README.md index facf0c5..4a234c3 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@

chartmogul-php provides convenient PHP bindings for ChartMogul's API.

- PHP Package - Build Status + + Build Status


diff --git a/composer.json b/composer.json index a7166a5..d4dae49 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,6 @@ "require-dev": { "php-http/mock-client": "^1.3", "guzzlehttp/psr7": "^1.0", - "http-interop/http-factory-guzzle": "^1.0", - "squizlabs/php_codesniffer": "^3.5" + "http-interop/http-factory-guzzle": "^1.0" } } diff --git a/src/Account.php b/src/Account.php index 016df45..b0b385c 100644 --- a/src/Account.php +++ b/src/Account.php @@ -15,21 +15,20 @@ */ class Account extends AbstractResource { - use ShowTrait; /** * @ignore */ - const RESOURCE_PATH = '/v1/account'; + public const RESOURCE_PATH = '/v1/account'; /** * @ignore */ - const RESOURCE_NAME = 'Account'; + public const RESOURCE_NAME = 'Account'; /** * @ignore */ - const ROOT_KEY = 'account'; + public const ROOT_KEY = 'account'; public $name; public $currency; diff --git a/src/Configuration.php b/src/Configuration.php index b5db9de..f7538af 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -1,6 +1,5 @@ getClient() ->setResourceKey(static::RESOURCE_NAME) @@ -242,7 +240,6 @@ public function removeCustomAttributes($custom) */ public function updateCustomAttributes($custom) { - $data = []; foreach (func_get_args() as $value) { $data = array_merge($data, $value); diff --git a/src/CustomerInvoices.php b/src/CustomerInvoices.php index 6117d26..9d759b4 100644 --- a/src/CustomerInvoices.php +++ b/src/CustomerInvoices.php @@ -8,18 +8,17 @@ class CustomerInvoices extends AbstractResource { - use \ChartMogul\Service\CreateTrait; use \ChartMogul\Service\AllTrait; /** * @ignore */ - const RESOURCE_PATH = '/v1/import/customers/:customer_uuid/invoices'; + public const RESOURCE_PATH = '/v1/import/customers/:customer_uuid/invoices'; /** * @ignore */ - const RESOURCE_NAME = 'Invoices'; + public const RESOURCE_NAME = 'Invoices'; public $invoices = []; @@ -46,7 +45,6 @@ public static function destroyAll($dataSourceUUID, $customerUUID) protected function setInvoice($index, $invoice) { - if ($invoice instanceof \ChartMogul\Invoice) { $this->invoices[$index] = $invoice; } elseif (is_array($invoice)) { diff --git a/src/Customers.php b/src/Customers.php index 43cb589..21b44c5 100644 --- a/src/Customers.php +++ b/src/Customers.php @@ -24,15 +24,15 @@ class Customers extends AbstractResource /** * @ignore */ - const RESOURCE_NAME = 'Customers'; + public const RESOURCE_NAME = 'Customers'; /** * @ignore */ - const RESOURCE_PATH = '/v1/customers'; + public const RESOURCE_PATH = '/v1/customers'; /** * @ignore */ - const ENTRY_CLASS = Customer::class; + public const ENTRY_CLASS = Customer::class; protected static function getEntryClass() { @@ -46,7 +46,6 @@ protected static function getEntryClass() */ public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/DataSource.php b/src/DataSource.php index 2292937..5877e66 100644 --- a/src/DataSource.php +++ b/src/DataSource.php @@ -16,7 +16,6 @@ */ class DataSource extends AbstractResource { - use CreateTrait; use AllTrait; use DestroyTrait; @@ -25,17 +24,17 @@ class DataSource extends AbstractResource /** * @ignore */ - const RESOURCE_PATH = '/v1/data_sources'; + public const RESOURCE_PATH = '/v1/data_sources'; /** * @ignore */ - const RESOURCE_NAME = 'Data Source'; + public const RESOURCE_NAME = 'Data Source'; /** * @ignore */ - const ROOT_KEY = 'data_sources'; + public const ROOT_KEY = 'data_sources'; protected $uuid; protected $status; diff --git a/src/Exceptions/ChartMogulException.php b/src/Exceptions/ChartMogulException.php index 1555607..87e2500 100644 --- a/src/Exceptions/ChartMogulException.php +++ b/src/Exceptions/ChartMogulException.php @@ -9,7 +9,6 @@ */ class ChartMogulException extends \RuntimeException implements ResponseException { - /** * @var int */ @@ -30,7 +29,6 @@ class ChartMogulException extends \RuntimeException implements ResponseException */ public function __construct($message, ResponseInterface $response = null, \Exception $previous = null) { - if ($response) { $response->getBody()->rewind(); $this->statusCode = $response->getStatusCode(); @@ -38,7 +36,7 @@ public function __construct($message, ResponseInterface $response = null, \Excep $body = $response->getBody()->getContents(); $json = json_decode($body, true); - $this->response = json_last_error() === JSON_ERROR_NONE? $json : $body; + $this->response = json_last_error() === JSON_ERROR_NONE ? $json : $body; // Adding body to message to get the whole error message to API user. $message = $message . " Response:\n " . $body; } diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index 711ffb9..4f3511d 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -8,5 +8,4 @@ */ class ForbiddenException extends ChartMogulException { - } diff --git a/src/Exceptions/NotAllowedException.php b/src/Exceptions/NotAllowedException.php index 57e8a3b..5334456 100644 --- a/src/Exceptions/NotAllowedException.php +++ b/src/Exceptions/NotAllowedException.php @@ -8,5 +8,4 @@ */ class NotAllowedException extends ChartMogulException { - } diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index ec5661c..be1441d 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -8,5 +8,4 @@ */ class NotFoundException extends ChartMogulException { - } diff --git a/src/Exceptions/ResourceInvalidException.php b/src/Exceptions/ResourceInvalidException.php index e77c9f4..ca19a40 100644 --- a/src/Exceptions/ResourceInvalidException.php +++ b/src/Exceptions/ResourceInvalidException.php @@ -8,5 +8,4 @@ */ class ResourceInvalidException extends ChartMogulException { - } diff --git a/src/Exceptions/SchemaInvalidException.php b/src/Exceptions/SchemaInvalidException.php index d591de5..f8e5001 100644 --- a/src/Exceptions/SchemaInvalidException.php +++ b/src/Exceptions/SchemaInvalidException.php @@ -8,5 +8,4 @@ */ class SchemaInvalidException extends ChartMogulException { - } diff --git a/src/Http/Client.php b/src/Http/Client.php index 13345b6..d453cd2 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -1,4 +1,5 @@ line_items[$index] = $line; } elseif (is_array($line) && isset($line['type']) && $line['type'] === 'one_time') { @@ -80,7 +79,6 @@ protected function setLineItem($index, $line) protected function setTransaction($index, $tr) { - if ($tr instanceof AbstractTransaction) { $this->transactions[$index] = $tr; } elseif (is_array($tr) && isset($tr['type']) && $tr['type'] === 'payment') { diff --git a/src/LineItems/AbstractLineItem.php b/src/LineItems/AbstractLineItem.php index d3c79f1..487d5fa 100644 --- a/src/LineItems/AbstractLineItem.php +++ b/src/LineItems/AbstractLineItem.php @@ -8,7 +8,6 @@ */ abstract class AbstractLineItem extends \ChartMogul\Resource\AbstractModel { - protected $uuid; public $type; diff --git a/src/LineItems/OneTime.php b/src/LineItems/OneTime.php index fa58f0f..1a7fca4 100644 --- a/src/LineItems/OneTime.php +++ b/src/LineItems/OneTime.php @@ -7,7 +7,6 @@ */ class OneTime extends AbstractLineItem { - public $type = 'one_time'; public $description; public $plan_uuid; diff --git a/src/LineItems/Subscription.php b/src/LineItems/Subscription.php index b326545..5f8038b 100644 --- a/src/LineItems/Subscription.php +++ b/src/LineItems/Subscription.php @@ -7,7 +7,6 @@ */ class Subscription extends AbstractLineItem { - public $type = 'subscription'; public $subscription_external_id; public $subscription_set_external_id; diff --git a/src/Metrics.php b/src/Metrics.php index 809616d..7f87e88 100644 --- a/src/Metrics.php +++ b/src/Metrics.php @@ -10,7 +10,6 @@ */ class Metrics { - /** * Retrieves all key metrics, for the specified time period. * @param array|array $options diff --git a/src/Metrics/ARPAs.php b/src/Metrics/ARPAs.php index 8da889a..f4863b7 100644 --- a/src/Metrics/ARPAs.php +++ b/src/Metrics/ARPAs.php @@ -7,13 +7,13 @@ class ARPAs extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = ARPA::class; + public const ENTRY_CLASS = ARPA::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/arpa'; + public const RESOURCE_PATH = '/v1/metrics/arpa'; /** * @ignore */ - const RESOURCE_NAME = 'ARPAs'; + public const RESOURCE_NAME = 'ARPAs'; } diff --git a/src/Metrics/ARRs.php b/src/Metrics/ARRs.php index 897f55b..d2267c7 100644 --- a/src/Metrics/ARRs.php +++ b/src/Metrics/ARRs.php @@ -7,13 +7,13 @@ class ARRs extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = ARR::class; + public const ENTRY_CLASS = ARR::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/arr'; + public const RESOURCE_PATH = '/v1/metrics/arr'; /** * @ignore */ - const RESOURCE_NAME = 'ARRs'; + public const RESOURCE_NAME = 'ARRs'; } diff --git a/src/Metrics/ASPs.php b/src/Metrics/ASPs.php index c2feb4b..87c5e58 100644 --- a/src/Metrics/ASPs.php +++ b/src/Metrics/ASPs.php @@ -7,13 +7,13 @@ class ASPs extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = ASP::class; + public const ENTRY_CLASS = ASP::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/asp'; + public const RESOURCE_PATH = '/v1/metrics/asp'; /** * @ignore */ - const RESOURCE_NAME = 'ASPs'; + public const RESOURCE_NAME = 'ASPs'; } diff --git a/src/Metrics/AbstractMetric.php b/src/Metrics/AbstractMetric.php index 236baec..b4d5348 100644 --- a/src/Metrics/AbstractMetric.php +++ b/src/Metrics/AbstractMetric.php @@ -10,7 +10,6 @@ class AbstractMetric extends AbstractResource { - use EntryTrait; use SummaryTrait; use AllTrait; @@ -22,7 +21,6 @@ protected static function getEntryClass() public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/Metrics/Activities.php b/src/Metrics/Activities.php index e9adeb1..9312394 100644 --- a/src/Metrics/Activities.php +++ b/src/Metrics/Activities.php @@ -9,21 +9,20 @@ class Activities extends AbstractResource { + use EntryTrait; + use AllTrait; /** * @ignore */ - const ENTRY_CLASS = Activity::class; + public const ENTRY_CLASS = Activity::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/activities'; + public const RESOURCE_PATH = '/v1/activities'; /** * @ignore */ - const RESOURCE_NAME = 'Activities'; - - use EntryTrait; - use AllTrait; + public const RESOURCE_NAME = 'Activities'; protected static function getEntryClass() { @@ -32,7 +31,6 @@ protected static function getEntryClass() public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/Metrics/Activity.php b/src/Metrics/Activity.php index 43afa8d..01d2c4f 100644 --- a/src/Metrics/Activity.php +++ b/src/Metrics/Activity.php @@ -23,7 +23,6 @@ */ class Activity extends AbstractModel { - protected $description; protected $type; protected $date; @@ -47,7 +46,6 @@ class Activity extends AbstractModel */ public static function all(array $options = [], ClientInterface $client = null) { - return Activities::all($options, $client); } } diff --git a/src/Metrics/AllKeyMetrics.php b/src/Metrics/AllKeyMetrics.php index 37d0723..6b27262 100644 --- a/src/Metrics/AllKeyMetrics.php +++ b/src/Metrics/AllKeyMetrics.php @@ -9,21 +9,20 @@ class AllKeyMetrics extends AbstractResource { + use EntryTrait; + use AllTrait; /** * @ignore */ - const ENTRY_CLASS = AllKeyMetric::class; + public const ENTRY_CLASS = AllKeyMetric::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/all'; + public const RESOURCE_PATH = '/v1/metrics/all'; /** * @ignore */ - const RESOURCE_NAME = 'All Key Metrics'; - - use EntryTrait; - use AllTrait; + public const RESOURCE_NAME = 'All Key Metrics'; protected static function getEntryClass() { @@ -32,7 +31,6 @@ protected static function getEntryClass() public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/Metrics/CustomerChurnRates.php b/src/Metrics/CustomerChurnRates.php index 90aeaee..8ccc97d 100644 --- a/src/Metrics/CustomerChurnRates.php +++ b/src/Metrics/CustomerChurnRates.php @@ -7,13 +7,13 @@ class CustomerChurnRates extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = CustomerChurnRate::class; + public const ENTRY_CLASS = CustomerChurnRate::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/customer-churn-rate'; + public const RESOURCE_PATH = '/v1/metrics/customer-churn-rate'; /** * @ignore */ - const RESOURCE_NAME = 'Customer Churn Rates'; + public const RESOURCE_NAME = 'Customer Churn Rates'; } diff --git a/src/Metrics/CustomerCounts.php b/src/Metrics/CustomerCounts.php index cd18cf1..d947bd0 100644 --- a/src/Metrics/CustomerCounts.php +++ b/src/Metrics/CustomerCounts.php @@ -7,13 +7,13 @@ class CustomerCounts extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = CustomerCount::class; + public const ENTRY_CLASS = CustomerCount::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/customer-count'; + public const RESOURCE_PATH = '/v1/metrics/customer-count'; /** * @ignore */ - const RESOURCE_NAME = 'Customer Counts'; + public const RESOURCE_NAME = 'Customer Counts'; } diff --git a/src/Metrics/Customers/Activities.php b/src/Metrics/Customers/Activities.php index cf97b9e..e022511 100644 --- a/src/Metrics/Customers/Activities.php +++ b/src/Metrics/Customers/Activities.php @@ -9,21 +9,20 @@ class Activities extends AbstractResource { + use EntryTrait; + use AllTrait; /** * @ignore */ - const ENTRY_CLASS = Activity::class; + public const ENTRY_CLASS = Activity::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/customers/:customer_uuid/activities'; + public const RESOURCE_PATH = '/v1/customers/:customer_uuid/activities'; /** * @ignore */ - const RESOURCE_NAME = 'Activities'; - - use EntryTrait; - use AllTrait; + public const RESOURCE_NAME = 'Activities'; protected static function getEntryClass() { @@ -32,7 +31,6 @@ protected static function getEntryClass() public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/Metrics/Customers/Activity.php b/src/Metrics/Customers/Activity.php index 6ff9228..aa2baf1 100644 --- a/src/Metrics/Customers/Activity.php +++ b/src/Metrics/Customers/Activity.php @@ -18,7 +18,6 @@ */ class Activity extends AbstractModel { - protected $id; protected $description; protected $type; @@ -37,7 +36,6 @@ class Activity extends AbstractModel */ public static function all(array $options = [], ClientInterface $client = null) { - return Activities::all($options, $client); } } diff --git a/src/Metrics/Customers/Subscription.php b/src/Metrics/Customers/Subscription.php index 111efdb..0cee1b2 100644 --- a/src/Metrics/Customers/Subscription.php +++ b/src/Metrics/Customers/Subscription.php @@ -21,7 +21,6 @@ */ class Subscription extends AbstractModel { - protected $id; protected $external_id; protected $plan; @@ -44,7 +43,6 @@ class Subscription extends AbstractModel */ public static function all(array $options = [], ClientInterface $client = null) { - return Subscriptions::all($options, $client); } } diff --git a/src/Metrics/Customers/Subscriptions.php b/src/Metrics/Customers/Subscriptions.php index 46c6f4e..b046053 100644 --- a/src/Metrics/Customers/Subscriptions.php +++ b/src/Metrics/Customers/Subscriptions.php @@ -9,21 +9,20 @@ class Subscriptions extends AbstractResource { + use EntryTrait; + use AllTrait; /** * @ignore */ - const ENTRY_CLASS = Subscription::class; + public const ENTRY_CLASS = Subscription::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/customers/:customer_uuid/subscriptions'; + public const RESOURCE_PATH = '/v1/customers/:customer_uuid/subscriptions'; /** * @ignore */ - const RESOURCE_NAME = 'Subscriptions'; - - use EntryTrait; - use AllTrait; + public const RESOURCE_NAME = 'Subscriptions'; protected static function getEntryClass() { @@ -32,7 +31,6 @@ protected static function getEntryClass() public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr, $client); $this->setEntries($this->entries); diff --git a/src/Metrics/LTVs.php b/src/Metrics/LTVs.php index bebd785..e871443 100644 --- a/src/Metrics/LTVs.php +++ b/src/Metrics/LTVs.php @@ -7,13 +7,13 @@ class LTVs extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = LTV::class; + public const ENTRY_CLASS = LTV::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/ltv'; + public const RESOURCE_PATH = '/v1/metrics/ltv'; /** * @ignore */ - const RESOURCE_NAME = 'LTVs'; + public const RESOURCE_NAME = 'LTVs'; } diff --git a/src/Metrics/MRRChurnRates.php b/src/Metrics/MRRChurnRates.php index f44bbc6..18e0c8e 100644 --- a/src/Metrics/MRRChurnRates.php +++ b/src/Metrics/MRRChurnRates.php @@ -7,13 +7,13 @@ class MRRChurnRates extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = MRRChurnRate::class; + public const ENTRY_CLASS = MRRChurnRate::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/mrr-churn-rate'; + public const RESOURCE_PATH = '/v1/metrics/mrr-churn-rate'; /** * @ignore */ - const RESOURCE_NAME = 'MRR Churn Rates'; + public const RESOURCE_NAME = 'MRR Churn Rates'; } diff --git a/src/Metrics/MRRs.php b/src/Metrics/MRRs.php index 72795ea..4ce6dfd 100644 --- a/src/Metrics/MRRs.php +++ b/src/Metrics/MRRs.php @@ -7,13 +7,13 @@ class MRRs extends AbstractMetric /** * @ignore */ - const ENTRY_CLASS = MRR::class; + public const ENTRY_CLASS = MRR::class; /** * @ignore */ - const RESOURCE_PATH = '/v1/metrics/mrr'; + public const RESOURCE_PATH = '/v1/metrics/mrr'; /** * @ignore */ - const RESOURCE_NAME = 'MRRs'; + public const RESOURCE_NAME = 'MRRs'; } diff --git a/src/Ping.php b/src/Ping.php index 6f6ca90..9ae0584 100644 --- a/src/Ping.php +++ b/src/Ping.php @@ -17,11 +17,11 @@ class Ping extends AbstractResource /** * @ignore */ - const RESOURCE_PATH = '/v1/ping'; + public const RESOURCE_PATH = '/v1/ping'; /** * @ignore */ - const RESOURCE_NAME = 'Ping'; + public const RESOURCE_NAME = 'Ping'; public $data; diff --git a/src/Plan.php b/src/Plan.php index 26f7ea8..ec10318 100644 --- a/src/Plan.php +++ b/src/Plan.php @@ -15,7 +15,6 @@ */ class Plan extends AbstractResource { - use AllTrait; use CreateTrait; use UpdateTrait; @@ -25,16 +24,16 @@ class Plan extends AbstractResource /** * @ignore */ - const RESOURCE_PATH = '/v1/plans'; - const RESOURCE_ID = 'plan_uuid'; + public const RESOURCE_PATH = '/v1/plans'; + public const RESOURCE_ID = 'plan_uuid'; /** * @ignore */ - const RESOURCE_NAME = 'Plan'; + public const RESOURCE_NAME = 'Plan'; /** * @ignore */ - const ROOT_KEY = 'plans'; + public const ROOT_KEY = 'plans'; protected $uuid; diff --git a/src/PlanGroup.php b/src/PlanGroup.php index 9c5fed5..ba64096 100644 --- a/src/PlanGroup.php +++ b/src/PlanGroup.php @@ -15,7 +15,6 @@ */ class PlanGroup extends AbstractResource { - use AllTrait; use CreateTrait; use UpdateTrait; @@ -25,16 +24,16 @@ class PlanGroup extends AbstractResource /** * @ignore */ - const RESOURCE_PATH = '/v1/plan_groups'; - const RESOURCE_ID = 'plan_group_uuid'; + public const RESOURCE_PATH = '/v1/plan_groups'; + public const RESOURCE_ID = 'plan_group_uuid'; /** * @ignore */ - const RESOURCE_NAME = 'PlanGroup'; + public const RESOURCE_NAME = 'PlanGroup'; /** * @ignore */ - const ROOT_KEY = 'plan_groups'; + public const ROOT_KEY = 'plan_groups'; protected $uuid; protected $plans_count; diff --git a/src/PlanGroups/Plan.php b/src/PlanGroups/Plan.php index d85c49b..20e20e4 100644 --- a/src/PlanGroups/Plan.php +++ b/src/PlanGroups/Plan.php @@ -16,11 +16,11 @@ class Plan extends AbstractResource /** * @ignore */ - const RESOURCE_PATH = '/v1/plan_groups/:plan_group_uuid/plans'; + public const RESOURCE_PATH = '/v1/plan_groups/:plan_group_uuid/plans'; /** * @ignore */ - const ROOT_KEY = 'plans'; + public const ROOT_KEY = 'plans'; protected $uuid; diff --git a/src/Resource/AbstractModel.php b/src/Resource/AbstractModel.php index f3ad99a..201bab2 100644 --- a/src/Resource/AbstractModel.php +++ b/src/Resource/AbstractModel.php @@ -2,7 +2,7 @@ namespace ChartMogul\Resource; -use \Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\ArrayCollection; abstract class AbstractModel { @@ -25,7 +25,7 @@ private function objectToArray($obj) $obj = $obj->toArray(); } - $data = is_object($obj)? get_object_vars($obj): $obj; + $data = is_object($obj) ? get_object_vars($obj) : $obj; if (is_array($data)) { return array_filter( diff --git a/src/Resource/AbstractResource.php b/src/Resource/AbstractResource.php index 781135a..39b3a8b 100644 --- a/src/Resource/AbstractResource.php +++ b/src/Resource/AbstractResource.php @@ -8,22 +8,20 @@ abstract class AbstractResource extends AbstractModel { - - /** * @ignore */ - const ROOT_KEY = null; + public const ROOT_KEY = null; /** * @ignore */ - const RESOURCE_PATH = null; + public const RESOURCE_PATH = null; /** * @ignore */ - const RESOURCE_NAME = null; + public const RESOURCE_NAME = null; /** @@ -39,7 +37,6 @@ abstract class AbstractResource extends AbstractModel */ public function __construct(array $attr = [], ClientInterface $client = null) { - parent::__construct($attr); if (is_null($client)) { diff --git a/src/Resource/EntryTrait.php b/src/Resource/EntryTrait.php index ccc3f6b..39cc140 100644 --- a/src/Resource/EntryTrait.php +++ b/src/Resource/EntryTrait.php @@ -6,7 +6,6 @@ trait EntryTrait { - protected $entries = []; protected function setEntries(array $entries = []) diff --git a/src/Resource/SummaryTrait.php b/src/Resource/SummaryTrait.php index aca622c..b58ee50 100644 --- a/src/Resource/SummaryTrait.php +++ b/src/Resource/SummaryTrait.php @@ -6,7 +6,6 @@ trait SummaryTrait { - protected $summary = []; protected function setSummary(array $summary = []) diff --git a/src/Service/AllTrait.php b/src/Service/AllTrait.php index 509b0e7..0f77aa3 100644 --- a/src/Service/AllTrait.php +++ b/src/Service/AllTrait.php @@ -1,4 +1,5 @@ setResourceClass(static::class) ->all($data); diff --git a/src/Service/CreateTrait.php b/src/Service/CreateTrait.php index 809205a..d9ab851 100644 --- a/src/Service/CreateTrait.php +++ b/src/Service/CreateTrait.php @@ -9,7 +9,6 @@ */ trait CreateTrait { - /** * Create a Resource * @param array $data @@ -18,7 +17,6 @@ trait CreateTrait */ public static function create(array $data = [], ClientInterface $client = null) { - return (new RequestService($client)) ->setResourceClass(static::class) ->create($data); diff --git a/src/Service/DestroyTrait.php b/src/Service/DestroyTrait.php index 68afef5..6b40b60 100644 --- a/src/Service/DestroyTrait.php +++ b/src/Service/DestroyTrait.php @@ -1,4 +1,5 @@ setResource($this) ->destroy(); diff --git a/src/Service/GetTrait.php b/src/Service/GetTrait.php index 0c4acc1..2b7b16f 100644 --- a/src/Service/GetTrait.php +++ b/src/Service/GetTrait.php @@ -1,4 +1,5 @@ resourceClass = $resourceClass; @@ -36,7 +36,7 @@ public function setResource(AbstractResource $resource) $this->resourceClass = get_class($resource); return $this; } - + /** * Use only when default class resource path must be overridden. * @param type $resourcePath @@ -64,7 +64,7 @@ private function applyResourcePath(&$data) if (isset($this->resourcePath)) { $path = $this->resourcePath; } - + foreach ($this->getNamedParams($path) as $param) { if (empty($data[$param])) { throw new \Exception('Parameter '.$param. ' is required'); @@ -105,15 +105,15 @@ public function create($data) public function update(array $id, array $data) { $class = $this->resourceClass; - - + + $response = $this->client ->setResourceKey($class::RESOURCE_NAME) ->send($this->applyResourcePath($id), 'PATCH', $data); return $class::fromArray($response, $this->client); } - + public function all($data) { $class = $this->resourceClass; diff --git a/src/Service/ShowTrait.php b/src/Service/ShowTrait.php index dacdc1e..d4cdbc1 100644 --- a/src/Service/ShowTrait.php +++ b/src/Service/ShowTrait.php @@ -1,4 +1,5 @@ setMethods(null) ->getMock(); - $this->assertEquals("chartmogul-php/1.1.0/PHP-".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION, $mock->getUserAgent()); + $this->assertEquals("chartmogul-php/4.0.0/PHP-".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION, $mock->getUserAgent()); } public function testGetBasicAuthHeader()