Completed
Pull Request — master (#13)
by
unknown
09:13
created

TranslationSheetServiceProvider::asArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2.0185
1
<?php
2
3
namespace Nikaia\TranslationSheet;
4
5
use Illuminate\Support\ServiceProvider;
6
use Nikaia\TranslationSheet\Util;
7
use Nikaia\TranslationSheet\Client\Client;
8
use Nikaia\TranslationSheet\Commands\Lock;
9
use Nikaia\TranslationSheet\Commands\Open;
10
use Nikaia\TranslationSheet\Commands\Prepare;
11
use Nikaia\TranslationSheet\Commands\Pull;
12
use Nikaia\TranslationSheet\Commands\Push;
13
use Nikaia\TranslationSheet\Commands\Setup;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Nikaia\TranslationSheet\Setup.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use Nikaia\TranslationSheet\Commands\Status;
15
use Nikaia\TranslationSheet\Commands\Unlock;
16
17
class TranslationSheetServiceProvider extends ServiceProvider
18 35
{
19
    public function boot()
20 35
    {
21 35
        $this->publishes([
22 35
            __DIR__.'/../config/config.php' => config_path('translation_sheet.php'),
23 35
        ], 'config');
24
    }
25 35
26
    public function register()
27 35
    {
28
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'translation_sheet');
29 35
30
        $this->registerGoogleApiClient();
31 35
32
        $this->registerSpreadsheet();
33 35
34 35
        $this->registerCommands();
35
    }
36 35
37
    private function registerGoogleApiClient()
38
    {
39 18
        $this->app->singleton(Client::class, function () {
40 18
            return Client::create(
41 18
                $this->app['config']['translation_sheet.serviceAccountCredentialsFile'],
42 18
                $this->app['config']['translation_sheet.googleApplicationName']
43 35
            );
44 35
        });
45
    }
46 35
47
    private function registerSpreadsheet()
48
    {
49 1
        $this->app->singleton(Spreadsheet::class, function () {
50 1
            return new Spreadsheet(
51 1
                $this->app['config']['translation_sheet.spreadsheetId'],
52 1
                Util::asArray($this->app['config']['translation_sheet.locales'])
53 35
            );
54 35
        });
55
    }
56 35
57
    private function registerCommands()
58 35
    {
59 35
        $this->commands([
60 35
            Setup::class,
61 35
            Push::class,
62 35
            Pull::class,
63 35
            Prepare::class,
64 35
            Lock::class,
65 35
            Unlock::class,
66 35
            Status::class,
67 35
            Open::class,
68 35
        ]);
69
    }
70
}
71