Skip to content

Commit

Permalink
Merge pull request #15 from nextapps-be/remove-docblocks-and-use-retu…
Browse files Browse the repository at this point in the history
…rntypes

Remove docblocks and use returntypes/typehints + drop support for old php and laravel versions
  • Loading branch information
gdebrauwer authored Jan 23, 2024
2 parents 77aeea4 + ea41a2f commit e541afa
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 402 deletions.
33 changes: 2 additions & 31 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,16 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
laravel: [7.*, 8.*, 9.*, 10.*]
php: [8.1, 8.2, 8.3]
laravel: [9.*, 10.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- php: 8.3
laravel: 9.*
dependency-version: prefer-lowest
- php: 8.3
laravel: 8.*
- php: 8.3
laravel: 7.*
- php: 8.2
laravel: 9.*
dependency-version: prefer-lowest
- php: 8.2
laravel: 8.*
- php: 8.2
laravel: 7.*
- php: 8.1
laravel: 8.*
dependency-version: prefer-lowest
- php: 8.1
laravel: 7.*
- php: 8.0
laravel: 8.*
dependency-version: prefer-lowest
- php: 8.0
laravel: 7.*
dependency-version: prefer-lowest
- php: 8.0
laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 10.*
- php: 7.3
laravel: 9.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
}
],
"require": {
"php": "^7.3|^7.4|^8.0|^8.1|^8.2|^8.3",
"php": "^8.1|^8.2|^8.3",
"guzzlehttp/guzzle": "^6.5|^7.0",
"illuminate/filesystem": "^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^7.0|^8.0|^9.0|^10.0",
"illuminate/filesystem": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"symfony/var-exporter": "^5.0|^6.0"
},
"require-dev": {
"adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0",
"orchestra/testbench": "^7.0|^8.0",
"phpunit/phpunit": "^9.1",
"squizlabs/php_codesniffer": "^3.6"
},
Expand Down
27 changes: 5 additions & 22 deletions src/Commands/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,17 @@
namespace NextApps\PoeditorSync\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use NextApps\PoeditorSync\Poeditor\Poeditor;
use NextApps\PoeditorSync\Translations\TranslationManager;

class DownloadCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'poeditor:download';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Download translations from POEditor';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle() : int
{
$this->getLocales()->each(function ($locale, $key) {
$translations = app(Poeditor::class)->download(is_string($key) ? $key : $locale);
Expand All @@ -38,14 +24,11 @@ public function handle()
});

$this->info('All translations have been downloaded!');

return Command::SUCCESS;
}

/**
* Get project locales.
*
* @return \Illuminate\Support\Collection
*/
protected function getLocales()
protected function getLocales() : Collection
{
return collect(config('poeditor-sync.locales'));
}
Expand Down
37 changes: 7 additions & 30 deletions src/Commands/UploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,18 @@

class UploadCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'poeditor:upload
{locale? : The language to upload translations from}
{--force : Overwrite the existing POEditor translations}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Upload translations to POEditor';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle() : int
{
if ($this->getLocale() === null) {
$this->error('Invalid locale provided!');

return 1;
return Command::FAILURE;
}

$translations = app(TranslationManager::class)->getTranslations($this->getLocale());
Expand All @@ -52,30 +37,22 @@ public function handle()
$this->line("{$response->getDeletedTermsCount()} terms deleted");
$this->line("{$response->getAddedTranslationsCount()} translations added");
$this->line("{$response->getUpdatedTranslationsCount()} translations updated");

return COMMAND::SUCCESS;
}

/**
* Get locale that needs to be used to upload translations.
*
* @return string|null
*/
protected function getLocale()
protected function getLocale() : ?string
{
$locale = $this->argument('locale') ?? app()->getLocale();

if (! collect(config('poeditor-sync.locales'))->flatten()->contains($locale)) {
return;
return null;
}

return $locale;
}

/**
* Get POEditor locale.
*
* @return string
*/
protected function getPoeditorLocale()
protected function getPoeditorLocale() : string
{
$locales = config('poeditor-sync.locales');

Expand Down
50 changes: 8 additions & 42 deletions src/Poeditor/Poeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,12 @@

class Poeditor
{
/**
* @var \GuzzleHttp\Client
*/
protected $client;

/**
* @var string
*/
protected $apiKey;

/**
* @var string
*/
protected $projectId;

/**
* Create a new manager instance.
*
* @param \GuzzleHttp\Client $client
* @param string $apiKey
* @param string $projectId
*
* @return void
*/
protected Client $client;

protected string $apiKey;

protected string $projectId;

public function __construct(Client $client, $apiKey, $projectId)
{
if (! is_string($apiKey) || ! $apiKey) {
Expand All @@ -46,14 +28,7 @@ public function __construct(Client $client, $apiKey, $projectId)
$this->projectId = $projectId;
}

/**
* Download translations in the language.
*
* @param string $language
*
* @return array
*/
public function download(string $language)
public function download(string $language) : array
{
$projectResponse = $this->client
->post(
Expand All @@ -80,16 +55,7 @@ public function download(string $language)
return json_decode($exportResponse, true);
}

/**
* Upload translations in the language.
*
* @param string $language
* @param array $translations
* @param bool $overwrite
*
* @return \NextApps\PoeditorSync\Poeditor\UploadResponse
*/
public function upload(string $language, array $translations, bool $overwrite = false)
public function upload(string $language, array $translations, bool $overwrite = false) : UploadResponse
{
$filename = stream_get_meta_data($file = tmpfile())['uri'] . '.json';

Expand Down
42 changes: 5 additions & 37 deletions src/Poeditor/UploadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,29 @@

class UploadResponse
{
/**
* The upload response content.
*
* @var array
*/
protected $content;
protected array $content;

/**
* Create a new POEditor upload response instance.
*
* @param array $content
*
* @return void
*/
public function __construct(array $content)
{
$this->content = $content;
}

/**
* Get the amount of terms that have been added.
*
* @return int
*/
public function getAddedTermsCount()
public function getAddedTermsCount() : int
{
return (int) $this->content['result']['terms']['added'];
}

/**
* Get the amount of terms that have been deleted.
*
* @return int
*/
public function getDeletedTermsCount()
public function getDeletedTermsCount() : int
{
return (int) $this->content['result']['terms']['deleted'];
}

/**
* Get the amount of translations that have been added.
*
* @return int
*/
public function getAddedTranslationsCount()
public function getAddedTranslationsCount() : int
{
return (int) $this->content['result']['translations']['added'];
}

/**
* Get the amount of translations that have been updated.
*
* @return int
*/
public function getUpdatedTranslationsCount()
public function getUpdatedTranslationsCount() : int
{
return (int) $this->content['result']['translations']['updated'];
}
Expand Down
10 changes: 2 additions & 8 deletions src/PoeditorSyncServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class PoeditorSyncServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
public function boot() : void
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand All @@ -27,10 +24,7 @@ public function boot()
}
}

/**
* Register the application services.
*/
public function register()
public function register() : void
{
$this->mergeConfigFrom(__DIR__ . '/../config/poeditor-sync.php', 'poeditor-sync');

Expand Down
Loading

0 comments on commit e541afa

Please sign in to comment.