TransArticlesServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 6
eloc 58
c 5
b 0
f 0
dl 0
loc 92
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 65 5
A register() 0 13 1
1
<?php
2
3
namespace Sirgrimorum\TransArticles;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Foundation\AliasLoader;
8
use Sirgrimorum\TransArticles\GetArticleFromDataBase;
9
use Illuminate\Support\Facades\Artisan;
10
11
class TransArticlesServiceProvider extends ServiceProvider {
12
13
    /**
14
     * Perform post-registration booting of services.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $this->publishes([
21
            __DIR__ . '/Config/transarticles.php' => config_path('sirgrimorum/transarticles.php'),
22
                ], 'config');
23
        $this->loadMigrationsFrom(__DIR__ . '/Migrations');
24
25
        Blade::directive('transarticles', function($nickname) {
26
            $translations = new \Sirgrimorum\TransArticles\GetArticleFromDataBase($this->app);
27
            return $translations->get(str_replace(['(', ')', ' ', '"', "'"], '', $nickname));
28
        });
29
        Blade::directive('transarticles_tojs', function($expression) {
30
            $auxExpression = explode(',', str_replace(['(', ')', ' ', '"', "'"], '', $expression));
31
            if (count($auxExpression) > 1)
32
            {
33
                $scope = $auxExpression[0];
34
                $basevar = $auxExpression[1];
35
            }
36
            else
37
            {
38
                $scope = $auxExpression[0];
39
                $basevar = "";
40
            }
41
            $translations = new \Sirgrimorum\TransArticles\GetArticleFromDataBase($this->app);
42
            return $translations->getjs($scope, $basevar);
43
        });
44
45
        Artisan::command('transarticles:createseed {--all : Create a seed for all database tables except migrations table} {--force : Force the iseed}', function () {
46
            $options = $this->options('all');
0 ignored issues
show
Bug introduced by
The method options() does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            /** @scrutinizer ignore-call */ $options = $this->options('all');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            if ($options['all']) {
48
                $dbName = env('DB_DATABASE');
49
50
                $query =  \DB::select("SHOW TABLES WHERE Tables_in_$dbName <> 'migrations'");
51
                $collection = new \Illuminate\Support\Collection($query);
52
                $tables = $collection->implode("Tables_in_$dbName",',');
53
                $options = $this->options('force');
54
                if ($options['force']) {
55
                    $nombre = "";
56
                }else{
57
                    $nombre = date("YmdHis");
58
                }
59
                $this->info('Calling iseed for all tables except migrations with suffix "{$nombre}" ...');
0 ignored issues
show
Bug introduced by
The method info() does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
                $this->/** @scrutinizer ignore-call */ info('Calling iseed for all tables except migrations with suffix "{$nombre}" ...');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
                $this->call('iseed', [
0 ignored issues
show
Bug introduced by
The method call() does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
                $this->/** @scrutinizer ignore-call */ call('iseed', [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
                    'tables' => $tables,
62
                    '--classnamesuffix' => $nombre,
63
                    '--chunksize' => "100",
64
                    '--force' => $options['force'],
65
                ]);
66
            }else{
67
                $bar = $this->output->createProgressBar(2);
0 ignored issues
show
Bug Best Practice introduced by
The property output does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. Did you maybe forget to declare it?
Loading history...
68
                $confirm = $this->choice("Do you wisth to clean the DatabaseSeeder.php list?", ['yes', 'no'], 0);
0 ignored issues
show
Bug introduced by
The method choice() does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
                /** @scrutinizer ignore-call */ $confirm = $this->choice("Do you wisth to clean the DatabaseSeeder.php list?", ['yes', 'no'], 0);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                $bar->advance();
70
                $nombre = date("YmdHis");
71
                if ($confirm == 'yes') {
72
                    $this->line("Creating seed archive of articles table and celaning DatabaseSeeder");
0 ignored issues
show
Bug introduced by
The method line() does not exist on Sirgrimorum\TransArticle...ArticlesServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
                    $this->/** @scrutinizer ignore-call */ line("Creating seed archive of articles table and celaning DatabaseSeeder");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
                    Artisan::call("iseed articles --classnamesuffix={$nombre} --chunksize=100 --clean");
74
                } else {
75
                    $this->line("Creating seed archive of articles table and adding to DatabaseSeeder list");
76
                    Artisan::call("iseed articles --classnamesuffix={$nombre} --chunksize=100");
77
                }
78
                $this->info("Seed file created with the name Articles{$nombre}Seeder.php");
79
                $bar->advance();
80
                $bar->finish();
81
            }
82
        })->describe('Create a seeder file with the current table Articles');
83
    }
84
85
    /**
86
     * Register any package services.
87
     *
88
     * @return void
89
     */
90
    public function register()
91
    {
92
        //AliasLoader::getInstance()->alias('TransArticles', GetArticleFromDataBase::class);
93
        $loader = AliasLoader::getInstance();
94
        $loader->alias(
95
                'TransArticles', GetArticleFromDataBase::class
96
        );
97
        $this->app->singleton(GetArticleFromDataBase::class, function($app) {
98
            return new GetArticleFromDataBase($app);
99
        });
100
        //$this->app->alias(GetArticleFromDataBase::class, 'TransArticles');
101
        $this->mergeConfigFrom(
102
                __DIR__ . '/Config/transarticles.php', 'sirgrimorum.transarticles'
103
        );
104
    }
105
106
}
107