Completed
Push — master ( 3291a6...0b0f34 )
by Nassif
07:30
created

TranslationSheetServiceProvider::asArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 6
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 21
{
19
    public function boot()
20 21
    {
21 21
        $this->publishes([
22 21
            __DIR__.'/../config/config.php' => config_path('translation_sheet.php'),
23 21
        ], 'config');
24
    }
25 21
26
    public function register()
27 21
    {
28
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'translation_sheet');
29 21
30
        $this->registerGoogleApiClient();
31 21
32
        $this->registerSpreadsheet();
33 21
34 21
        $this->registerCommands();
35
    }
36 21
37
    private function registerGoogleApiClient()
38
    {
39 14
        $this->app->singleton(Client::class, function () {
40 14
            return Client::create(
41 14
                $this->app['config']['translation_sheet.serviceAccountCredentialsFile'],
42
                $this->app['config']['translation_sheet.googleApplicationName']
43 21
            );
44 21
        });
45
    }
46 21
47
    private function registerSpreadsheet()
48
    {
49
        $this->app->singleton(Spreadsheet::class, function () {
50
            return new Spreadsheet(
51
                $this->app['config']['translation_sheet.spreadsheetId'],
52
                Util::asArray($this->app['config']['translation_sheet.locales'])
53 21
            );
54 21
        });
55
    }
56 21
57
    private function registerCommands()
58 21
    {
59 21
        $this->commands([
60
            Setup::class,
61
            Push::class,
62
            Pull::class,
63
            Prepare::class,
64
            Lock::class,
65
            Unlock::class,
66
            Status::class,
67
            Open::class,
68 21
        ]);
69
    }
70
}
71