MyModuleBase::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Modules Dependencies
4
 * Webino Example
5
 */
6
7
use WebinoAppLib\Application\AbstractApplication;
8
use WebinoAppLib\Event\RouteEvent;
9
use WebinoAppLib\Feature\Modules;
10
use WebinoAppLib\Feature\Service;
11
use WebinoAppLib\Module\AbstractModule;
12
use WebinoAppLib\Response\Content\SourcePreview;
13
use WebinoAppLib\Router\DefaultRoute;
14
15
require __DIR__ . '/../../vendor/autoload.php';
16
17
/**
18
 * Custom base module
19
 */
20
class MyModuleBase extends AbstractModule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
21
{
22
    public function getConfig()
23
    {
24
        return [
25
            new Service(MyModuleService::class),
26
        ];
27
    }
28
}
29
30
/**
31
 * Custom module
32
 */
33 View Code Duplication
class MyModule extends AbstractModule
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type MyModule has been defined more than once; this definition is ignored, only the first definition in examples/simple/public/m...s-config-TODO/index.php (L21-47) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
{
35
    const VERSION = '0.1.0';
36
37
    public function getDependencies()
38
    {
39
        return [
40
            MyModuleBase::class,
41
        ];
42
    }
43
44
    protected function init(AbstractApplication $app)
45
    {
46
        /**
47
         * Binding to default route
48
         * from the custom module.
49
         */
50
        $app->bind(DefaultRoute::class, function (RouteEvent $event) {
51
            /**
52
             * Obtaining custom
53
             * module service.
54
             */
55
            $myService = $event->getApp()->get(MyModuleService::class);
56
57
            $event->setResponse([
58
                $myService->doSomething(),
59
                new SourcePreview(__FILE__),
60
            ]);
61
        });
62
    }
63
}
64
65
/**
66
 * Custom module service
67
 */
68
class MyModuleService
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type MyModuleService has been defined more than once; this definition is ignored, only the first definition in examples/simple/public/m...s-config-TODO/index.php (L87-93) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
69
{
70
    public function doSomething()
71
    {
72
        return 'My custom module response text!';
73
    }
74
}
75
76
$config = Webino::config([
77
    /**
78
     * Configuring app
79
     * modules.
80
     */
81
    new Modules([
82
        MyModule::class,
83
    ]),
84
]);
85
86
$debugger = Webino::debugger(Webino::debuggerOptions()->setDevMode()->setBar());
87
88
Webino::application($config, $debugger)->bootstrap()->dispatch();
89