Skip to content
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

Solve SF 7 deprecation #8

Merged
merged 4 commits into from
Aug 12, 2024
Merged
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
39 changes: 39 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Checks

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 1

- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2
ini-file: development

- run: composer install

- name: Run php-cs-fixer
if: always()
run: php vendor/bin/php-cs-fixer --dry-run --diff fix

- name: Run phpstan
if: always()
run: php vendor/bin/phpstan
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.idea
composer.lock
/vendor/

.php-cs-fixer.cache
.php-cs-fixer.dist
56 changes: 56 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

$finder = PhpCsFixer\Finder::create()
->files()
->in(__DIR__)
->exclude('vendor')
->name('*.php');

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->setRules([
'@PHP82Migration' => true,
'@Symfony' => true,
'@Symfony:risky' => true,

// Override Symfony config
'method_argument_space' => [
'after_heredoc' => true,
'on_multiline' => 'ensure_fully_multiline',
'attribute_placement' => 'same_line',
],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'single_line_throw' => false,

// Added rules
'array_indentation' => true,
'attribute_empty_parentheses' => true,
'explicit_string_variable' => true,
'general_phpdoc_annotation_remove' => [
'annotations' => ['author', 'since', 'package', 'subpackage', 'group'],
],
'header_comment' => ['header' => ''],
'no_superfluous_elseif' => true,
'no_useless_else' => true,
'nullable_type_declaration_for_default_null_value' => true,
'operator_linebreak' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_separation' => ['groups' => [
[
'phpstan-template',
'phpstan-template-covariant',
'phpstan-extends',
'phpstan-implements',
'phpstan-var',
'phpstan-param',
'phpstan-return',
],
['Assert\\*', 'EmailCheckerAssert\\*', 'WeglotAssert\\*'],
['ORM\\*'],
['Groups', 'SerializedName'],
]],
'phpdoc_to_comment' => ['ignored_tags' => ['phpstan-var', 'phpstan-throws']],
'php_unit_test_case_static_method_calls' => true,
])
->setFinder($finder);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "3.60.*",
"phpstan/phpstan": "1.11.*",
"phpstan/phpstan-strict-rules": "1.6.*",
"phpstan/phpstan-symfony": "1.4.*"
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WeglotTextMasterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class WeglotTextMasterExtension extends Extension
{
Expand Down
15 changes: 8 additions & 7 deletions src/Service/TextMasterApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class TextMasterApi
'addDocument' => ['method' => 'POST', 'url' => 'clients/projects/{projectId}/documents'],
'completeDocument' => ['method' => 'PUT', 'url' => 'clients/projects/{projectId}/documents/{documentId}/complete'],
'getDocument' => ['method' => 'GET', 'url' => 'clients/projects/{projectId}/documents/{documentId}'],
'getAbilities' => ['method'=> 'GET', 'url' => 'clients/abilities?activity=translation&page={page}'],
'getAbilities' => ['method' => 'GET', 'url' => 'clients/abilities?activity=translation&page={page}'],
'getAuthorsForProject' => ['method' => 'GET', 'url' => 'clients/projects/{projectId}/my_authors?status={status}'],
'getCategories' => ['method' => 'GET', 'url' => 'public/categories'],
'setOptions' => ['method' => 'PUT', 'url' => 'clients/projects/{projectId}/activate_tm_options']
'setOptions' => ['method' => 'PUT', 'url' => 'clients/projects/{projectId}/activate_tm_options'],
];

public function __construct(string $apiKey, string $apiSecret, string $textmasterEnv)
Expand Down Expand Up @@ -174,7 +174,7 @@ public function getCategories(): ResponseInterface
public function getAbilities(string $page): ResponseInterface
{
$routeParams = self::ROUTES['getAbilities'];
$url = $this->formatUrl($routeParams['url'],['{page}' => $page]);
$url = $this->formatUrl($routeParams['url'], ['{page}' => $page]);

return $this->request($url, $routeParams['method']);
}
Expand Down Expand Up @@ -204,14 +204,15 @@ public function extractErrorFromResponse(ResponseInterface $response, string $fo
if (
!\is_array($decodedResponse)
|| !isset($decodedResponse['errors'])
|| !\is_iterable($decodedResponse['errors'])
|| !is_iterable($decodedResponse['errors'])
) {
return $errorMsg;
}

foreach ($decodedResponse['errors'] as $type => $messagesArray) {
$errorMsg .= "Type of error: $type ".$lineBreaker;
if (is_array($messagesArray)) {
$errorMsg .= "Type of error: {$type} ".$lineBreaker;
if (\is_array($messagesArray)) {
/** @var string $msg */
foreach ($messagesArray as $msg) {
$errorMsg .= $msg.$lineBreaker;
}
Expand Down Expand Up @@ -246,7 +247,7 @@ private function createGuzzleClient(array $options): Client
->withHeader('Apikey', $options['key'])
->withHeader('Date', $date->format('Y-m-d H:i:s'))
->withHeader('Signature', sha1($options['secret'].$date->format('Y-m-d H:i:s')))
;
;
}));

unset($options['key'], $options['secret']);
Expand Down