Passed
Pull Request — master (#355)
by
unknown
01:36
created

ViewProvider.php$0 ➔ compileFunction()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
cc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Providers;
6
7
use function Canvas\Core\appPath;
8
use Phalcon\Cache\Backend\File as BackendFileCache;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Backend\File was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Phalcon\Cache\Frontend\None as NoneCache;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Frontend\None was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Phalcon\Cache\Frontend\Output as FrontenCacheOutput;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cache\Frontend\Output was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Phalcon\Di\ServiceProviderInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di\ServiceProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\View\Engine\Volt was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Phalcon\Mvc\View\Simple as SimpleView;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\View\Simple was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
class ViewProvider implements ServiceProviderInterface
17
{
18
    /**
19
     * @param DiInterface $container
20
     */
21
    public function register(DiInterface $container)
22
    {
23
        $config = $container->get('config');
24
25
        /**
26
         * Setting up the view component.
27
         */
28
        $container->set('view', function () use ($config, $container) {
0 ignored issues
show
Unused Code introduced by
The import $container is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
29
            $view = new SimpleView();
30
            $view->setViewsDir($config->filesystem->local->path . '/view/');
31
            $view->registerEngines([
32
                '.volt' => function ($view, $container) use ($config) {
33
                    $volt = new VoltEngine($view, $container);
34
                    $volt->setOptions([
35
                        //CACHE save DISABLED IN DEV ENVIRONMENT
36
                        'compiledPath' => appPath('storage/cache/volt/'),
37
                        'compiledSeparator' => '_',
38
                        'compileAlways' => !$config->app->production,
39
                    ]);
40
41
                    $volt->getCompiler()->addExtension(new class {
42
                        /**
43
                         * This method is called for any PHP function on the volt.
44
                         */
45
                        public function compileFunction($name, $arguments)
46
                        {
47
                            if (function_exists($name)) {
48
                                return "{$name}({$arguments})";
49
                            }
50
                        }
51
                    });
52
53
                    return $volt;
54
                },
55
            ]);
56
57
            return $view;
58
        });
59
60
        /**
61
         * View cache.
62
         */
63
        $container->set(
64
            'viewCache',
65
            function () use ($config) {
66
                if (!$config->app->production) {
67
                    $frontCache = new NoneCache();
68
                } else {
69
                    //Cache data for one day by default
70
                    $frontCache = new FrontenCacheOutput([
71
                        'lifetime' => 172800,
72
                    ]);
73
                }
74
                return new BackendFileCache($frontCache, [
75
                    'cacheDir' => appPath('storage/cache/volt/'),
76
                    'prefix' => $config->app->id . '-',
77
                ]);
78
            }
79
        );
80
    }
81
}
82