Passed
Branch feature/2.0 (9789a8)
by Jonathan
14:17
created

ModuleMyArtJaubTrait::customModuleSupportUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * webtrees-lib: MyArtJaub library for webtrees
4
 *
5
 * @package MyArtJaub\Webtrees
6
 * @author Jonathan Jaubart <[email protected]>
7
 * @copyright Copyright (c) 2020, Jonathan Jaubart
8
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
9
 */
10
declare(strict_types=1);
11
12
namespace MyArtJaub\Webtrees\Module;
13
14
use Aura\Router\RouterContainer;
15
use Fisharebest\Localization\Translation;
16
use Fisharebest\Webtrees\View;
17
use Fisharebest\Webtrees\Webtrees;
18
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
19
use Fisharebest\Webtrees\Module\ModuleThemeInterface;
20
21
/**
22
 * MyArtJaub Module
23
 */
24
trait ModuleMyArtJaubTrait
25
{    
26
    use ModuleCustomTrait;
27
    
28
    /**
29
     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
30
     */
31
    public function boot() : void
32
    {
33
        View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
0 ignored issues
show
Bug introduced by
It seems like name() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

33
        View::registerNamespace($this->/** @scrutinizer ignore-call */ name(), $this->resourcesFolder() . 'views/');
Loading history...
34
        
35
        $this->loadRoutes(app(RouterContainer::class)->getMap());
0 ignored issues
show
Bug introduced by
It seems like loadRoutes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

35
        $this->/** @scrutinizer ignore-call */ 
36
               loadRoutes(app(RouterContainer::class)->getMap());
Loading history...
36
    }
37
    
38
    /**
39
     * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder()
40
     */
41
    public function resourcesFolder(): string
42
    {
43
        return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/';
44
    }
45
    
46
    /**
47
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
48
     */
49
    public function customModuleAuthorName() : string
50
    {
51
        return 'Jonathan Jaubart';
52
    }
53
    
54
    /**
55
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
56
     */
57
    public function customModuleSupportUrl() : string
58
    {
59
        return 'https://github.com/jon48/webtrees-lib';
60
    }
61
    
62
    /**
63
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations()
64
     */
65
    public function customTranslations(string $language) : array
66
    {
67
        $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php';
68
        
69
        try {
70
            $translation  = new Translation($translation_file);
71
            return $translation->asArray();
72
        } catch (\Exception $e) { }
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
73
        
74
        return array();
75
    }
76
    
77
    /**
78
     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl
79
     */
80
    public function moduleCssUrl() : string
81
    {
82
        /** @var ModuleThemeInterface $theme */
83
        $theme = app(ModuleThemeInterface::class);
84
        $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
85
        
86
        if(file_exists($css_file)) {
87
            return $this->assetUrl('css/' . $theme->name() . '.min.css');
88
        }
89
        else {
90
            return $this->assetUrl('css/default.min.css');
91
        }
92
    }
93
    
94
}
95