Skip to content

✨ Add some new features to assets api + tests upgrade #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Run PHPStan
uses: docker://jakzal/phpqa:php7.3-alpine
uses: docker://jakzal/phpqa:php8.1-alpine
with:
args: phpstan analyze

Expand All @@ -17,17 +17,6 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Run PHP-CS-Fixer
uses: docker://jakzal/phpqa:php7.3-alpine
uses: docker://jakzal/phpqa:php8.1-alpine
with:
args: php-cs-fixer fix --dry-run --diff-format udiff -vvv

roave-bc-check:
name: Roave BC Check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Roave BC Check
uses: docker://nyholm/roave-bc-check-ga
args: php-cs-fixer fix --dry-run -vvv
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0' ]
php: [ '7.4', '8.0', '8.1', '8.2' ]
strategy: [ 'highest' ]
include:
- php: 7.4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.php_cs.cache
/.php-cs-fixer.cache
/composer.lock
/phpunit.xml
/vendor/
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@Symfony' => true,
])
->setFinder($finder)
;
13 changes: 0 additions & 13 deletions .php_cs

This file was deleted.

5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,3 @@ parameters:
count: 1
path: src/Model/Translation/Translation.php

-
message: "#^Property FAPI\\\\Localise\\\\RequestBuilder\\:\\:\\$multipartStreamBuilder has unknown class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder as its type\\.$#"
count: 1
path: src/RequestBuilder.php

-
message: "#^Parameter \\$multipartStreamBuilder of method FAPI\\\\Localise\\\\RequestBuilder\\:\\:__construct\\(\\) has invalid typehint type Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder\\.$#"
count: 2
path: src/RequestBuilder.php

-
message: "#^Instantiated class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder not found\\.$#"
count: 1
path: src/RequestBuilder.php

-
message: "#^Call to method addResource\\(\\) on an unknown class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder\\.$#"
count: 1
path: src/RequestBuilder.php

-
message: "#^Call to method build\\(\\) on an unknown class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder\\.$#"
count: 1
path: src/RequestBuilder.php

-
message: "#^Call to method getBoundary\\(\\) on an unknown class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder\\.$#"
count: 1
path: src/RequestBuilder.php

-
message: "#^Call to method reset\\(\\) on an unknown class Http\\\\Message\\\\MultipartStream\\\\MultipartStreamBuilder\\.$#"
count: 1
path: src/RequestBuilder.php

2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ parameters:
level: 3
paths:
- src
excludes_analyse:
excludePaths:
- vendor
34 changes: 24 additions & 10 deletions src/Api/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@

namespace FAPI\Localise\Api;

use FAPI\Localise\Exception;
use FAPI\Localise\Model\Asset\Asset as AssetModel;
use FAPI\Localise\Model\Asset\TagDeleted;
use Psr\Http\Message\ResponseInterface;
use FAPI\Localise\Exception;

/**
* @author Tobias Nyholm <[email protected]>
*/
class Asset extends HttpApi
{
/**
* Get an asset.
* {@link https://localise.biz/api/docs/assets/getasset}.
*/
public function get(string $projectKey, string $id): AssetModel
{
$response = $this->httpGet(sprintf('/api/assets/%s.json?key=%s', $id, $projectKey));

return $this->hydrator->hydrate($response, AssetModel::class);
}

/**
* Create an asset.
* {@link https://localise.biz/api/docs/assets/createasset}.
*
* @param string $projectKey
* @param string $id
*
* @return AssetModel|ResponseInterface
*
* @throws Exception
Expand Down Expand Up @@ -58,10 +67,6 @@ public function create(string $projectKey, string $id)
* Tag an asset.
* {@link https://localise.biz/api/docs/assets/tagasset}.
*
* @param string $projectKey
* @param string $id
* @param string $tag
*
* @return AssetModel|ResponseInterface
*
* @throws Exception\DomainException
Expand All @@ -88,8 +93,6 @@ public function tag(string $projectKey, string $id, string $tag)
* Patch an asset.
* {@link https://localise.biz/api/docs/assets/patchasset}.
*
* @param string $projectKey
* @param string $id
* @param string $type
* @param string $name
* @param string $context
Expand Down Expand Up @@ -133,4 +136,15 @@ public function patch(string $projectKey, string $id, $type = null, $name = null

return $this->hydrator->hydrate($response, AssetModel::class);
}

/**
* Delete a tag.
* {@link https://localise.biz/api/docs/assets/untagasset}.
*/
public function deleteTag(string $projectKey, string $assetId, string $tag): TagDeleted
{
$response = $this->httpDelete(sprintf('/api/assets/%s/tags/%s.json?key=%s', $assetId, $tag, $projectKey));

return $this->hydrator->hydrate($response, TagDeleted::class);
}
}
7 changes: 1 addition & 6 deletions src/Api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace FAPI\Localise\Api;

use Psr\Http\Message\ResponseInterface;
use FAPI\Localise\Exception;
use Psr\Http\Message\ResponseInterface;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -21,11 +21,6 @@ class Export extends HttpApi
* Export a locale.
* {@link https://localise.biz/api/docs/export/exportlocale}.
*
* @param string $projectKey
* @param string $locale
* @param string $ext
* @param array $params
*
* @return string|ResponseInterface
*
* @throws Exception
Expand Down
23 changes: 2 additions & 21 deletions src/Api/HttpApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

use FAPI\Localise\Exception\Domain as DomainExceptions;
use FAPI\Localise\Exception\DomainException;
use FAPI\Localise\Hydrator\NoopHydrator;
use Http\Client\HttpClient;
use FAPI\Localise\Hydrator\Hydrator;
use FAPI\Localise\Hydrator\NoopHydrator;
use FAPI\Localise\RequestBuilder;
use Http\Client\HttpClient;
use Psr\Http\Message\ResponseInterface;

/**
Expand All @@ -37,11 +37,6 @@ abstract class HttpApi
*/
protected $requestBuilder;

/**
* @param HttpClient $httpClient
* @param RequestBuilder $requestBuilder
* @param Hydrator $hydrator
*/
public function __construct(HttpClient $httpClient, Hydrator $hydrator, RequestBuilder $requestBuilder)
{
$this->httpClient = $httpClient;
Expand All @@ -57,8 +52,6 @@ public function __construct(HttpClient $httpClient, Hydrator $hydrator, RequestB
* @param string $path Request path
* @param array $params GET parameters
* @param array $requestHeaders Request Headers
*
* @return ResponseInterface
*/
protected function httpGet(string $path, array $params = [], array $requestHeaders = []): ResponseInterface
{
Expand All @@ -77,8 +70,6 @@ protected function httpGet(string $path, array $params = [], array $requestHeade
* @param string $path Request path
* @param array $params POST parameters to be JSON encoded
* @param array $requestHeaders Request headers
*
* @return ResponseInterface
*/
protected function httpPost(string $path, array $params = [], array $requestHeaders = []): ResponseInterface
{
Expand All @@ -93,8 +84,6 @@ protected function httpPost(string $path, array $params = [], array $requestHead
* @param string $path Request path
* @param array|string $body Request body
* @param array $requestHeaders Request headers
*
* @return ResponseInterface
*/
protected function httpPostRaw(string $path, $body, array $requestHeaders = []): ResponseInterface
{
Expand All @@ -109,8 +98,6 @@ protected function httpPostRaw(string $path, $body, array $requestHeaders = []):
* @param string $path Request path
* @param array $params POST parameters to be JSON encoded
* @param array $requestHeaders Request headers
*
* @return ResponseInterface
*/
protected function httpPut(string $path, array $params = [], array $requestHeaders = []): ResponseInterface
{
Expand All @@ -127,8 +114,6 @@ protected function httpPut(string $path, array $params = [], array $requestHeade
* @param string $path Request path
* @param array $params PATCH parameters to be JSON encoded
* @param array $requestHeaders Request headers
*
* @return ResponseInterface
*/
protected function httpPatch(string $path, array $params = [], array $requestHeaders = []): ResponseInterface
{
Expand All @@ -145,8 +130,6 @@ protected function httpPatch(string $path, array $params = [], array $requestHea
* @param string $path Request path
* @param array $params POST parameters to be JSON encoded
* @param array $requestHeaders Request headers
*
* @return ResponseInterface
*/
protected function httpDelete(string $path, array $params = [], array $requestHeaders = []): ResponseInterface
{
Expand All @@ -162,8 +145,6 @@ protected function httpDelete(string $path, array $params = [], array $requestHe
*
* Call is controlled by the specific API methods.
*
* @param ResponseInterface $response
*
* @throws DomainException
*/
protected function handleErrors(ResponseInterface $response)
Expand Down
7 changes: 1 addition & 6 deletions src/Api/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace FAPI\Localise\Api;

use FAPI\Localise\Exception;
use FAPI\Localise\Model\Import\Imported;
use Psr\Http\Message\ResponseInterface;
use FAPI\Localise\Exception;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -22,11 +22,6 @@ class Import extends HttpApi
* Export a locale.
* {@link https://localise.biz/api/docs/export/exportlocale}.
*
* @param string $projectKey
* @param string $ext
* @param string $body
* @param array $params
*
* @return string|ResponseInterface
*
* @throws Exception
Expand Down
17 changes: 2 additions & 15 deletions src/Api/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace FAPI\Localise\Api;

use FAPI\Localise\Model\Translation\TranslationDeleted;
use FAPI\Localise\Exception;
use FAPI\Localise\Model\Translation\Translation as TranslationModel;
use FAPI\Localise\Model\Translation\TranslationDeleted;
use Psr\Http\Message\ResponseInterface;
use FAPI\Localise\Exception;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -23,10 +23,6 @@ class Translation extends HttpApi
* Get a translation.
* {@link https://localise.biz/api/docs/translations/gettranslation}.
*
* @param string $projectKey
* @param string $id
* @param string $locale
*
* @return TranslationModel|ResponseInterface
*
* @throws Exception
Expand All @@ -50,11 +46,6 @@ public function get(string $projectKey, string $id, string $locale)
* Create a new translation.
* {@link https://localise.biz/api/docs/translations/translate}.
*
* @param string $projectKey
* @param string $id
* @param string $locale
* @param string $translation
*
* @return TranslationModel|ResponseInterface
*
* @throws Exception
Expand All @@ -77,10 +68,6 @@ public function create(string $projectKey, string $id, string $locale, string $t
* Delete translation
* {@link https://localise.biz/api/docs/translations/untranslate}.
*
* @param string $projectKey
* @param string $id
* @param string $locale
*
* @return TranslationDeleted|ResponseInterface
*
* @throws Exception
Expand Down
Loading