generated from fidum/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
282 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Fidum\LaravelTranslationLinter\Managers; | ||
|
||
use Fidum\LaravelTranslationLinter\Contracts\Readers\LanguageFileReader; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Support\Manager; | ||
|
||
/** | ||
* @method LanguageFileReader driver(string $driver) | ||
*/ | ||
class LanguageFileReaderManager extends Manager | ||
{ | ||
public function __construct( | ||
Container $container, | ||
protected array $driverConfig, | ||
) { | ||
parent::__construct($container); | ||
|
||
foreach ($this->driverConfig as $driver => $readerClass) { | ||
$this->extend($driver, fn (Container $app) => $app->get($readerClass)); | ||
} | ||
} | ||
|
||
public function getDefaultDriver() | ||
{ | ||
return array_key_first($this->customCreators); | ||
} | ||
|
||
public function isEnabled(string $driver) | ||
{ | ||
return array_key_exists($driver, $this->customCreators); | ||
} | ||
|
||
public function getEnabledDrivers() | ||
{ | ||
return array_keys($this->customCreators); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Fidum\LaravelTranslationLinter\Readers; | ||
|
||
use Fidum\LaravelTranslationLinter\Contracts\Readers\LanguageFileReader as LanguageFileReaderContract; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
class JsonFileReader implements LanguageFileReaderContract | ||
{ | ||
public function execute(SplFileInfo $file): array | ||
{ | ||
$translations = json_decode($file->getContents(), true); | ||
|
||
if (! is_array($translations)) { | ||
throw new InvalidArgumentException("Unable to extract an array from {$file->getPathname()}!"); | ||
} | ||
|
||
return $translations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Fidum\LaravelTranslationLinter\Readers; | ||
|
||
use Fidum\LaravelTranslationLinter\Contracts\Readers\LanguageFileReader as LanguageFileReaderContract; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
class PhpFileReader implements LanguageFileReaderContract | ||
{ | ||
public function execute(SplFileInfo $file): array | ||
{ | ||
$translations = include $file->getPathname(); | ||
|
||
if (! is_array($translations)) { | ||
throw new InvalidArgumentException("Unable to extract an array from {$file->getPathname()}!"); | ||
} | ||
|
||
return $translations; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
tests/.pest/snapshots/Commands/UnusedCommandTest/it_can_test_with_default_no_fields.snap
This file was deleted.
Oops, something went wrong.
4 changes: 3 additions & 1 deletion
4
...est/it_can_test_with_default_filters.snap → ...dTest/it_errors_with_default_filters.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/.pest/snapshots/Commands/UnusedCommandTest/it_errors_with_default_no_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
ERROR 11 unused translations found. | ||
|
4 changes: 3 additions & 1 deletion
4
.../it_can_test_with_default_no_filters.snap → ...st/it_errors_with_default_no_filters.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
..._test_with_default_restricted_fields.snap → ...rrors_with_default_restricted_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tests/.pest/snapshots/Commands/UnusedCommandTest/it_errors_with_multiple_locales.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
ERROR 22 unused translations found. | ||
|
||
+--------+-----------+------------------------------------+----------------------------------------------------+ | ||
| Locale | Namespace | Key | Value | | ||
+--------+-----------+------------------------------------+----------------------------------------------------+ | ||
| en | | Unused PHP Class | I am unused in php class | | ||
| en | | Unused Blade File | I am unused in blade | | ||
| en | | Unused Vue Component | I am unused in vue component | | ||
| en | | example.unused | I am unused in php class | | ||
| en | | example.blade.choice.unused | I am unused in blade | | ||
| en | | example.blade.lang.unused | I am unused in blade | | ||
| en | | example.vue.unused | I am unused in vue component | | ||
| en | | folder/example.unused | I am unused in php class | | ||
| en | | folder/example.blade.choice.unused | I am unused in blade | | ||
| en | | folder/example.blade.lang.unused | I am unused in blade | | ||
| en | | folder/example.vue.unused | I am unused in vue component | | ||
| de | | Unused PHP Class | Ich werde in einer PHP-Klasse nicht verwendet | | ||
| de | | Unused Blade File | Ich werde in Blade nicht verwendet | | ||
| de | | Unused Vue Component | Ich werde in einem Vue-Komponenten nicht verwendet | | ||
| de | | example.unused | Ich werde in einer PHP-Klasse nicht verwendet | | ||
| de | | example.blade.choice.unused | Ich werde in Blade nicht verwendet | | ||
| de | | example.blade.lang.unused | Ich werde in Blade nicht verwendet | | ||
| de | | example.vue.unused | Ich werde in einem Vue-Komponenten nicht verwendet | | ||
| de | | folder/example.unused | Ich werde in einer PHP-Klasse nicht verwendet | | ||
| de | | folder/example.blade.choice.unused | Ich werde in Blade nicht verwendet | | ||
| de | | folder/example.blade.lang.unused | Ich werde in Blade nicht verwendet | | ||
| de | | folder/example.vue.unused | Ich werde in einem Vue-Komponenten nicht verwendet | | ||
+--------+-----------+------------------------------------+----------------------------------------------------+ |
3 changes: 3 additions & 0 deletions
3
...mands/UnusedCommandTest/it_outputs_success_message_when_no_unused_translations_found.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
INFO No unused translations found! | ||
|
Oops, something went wrong.