Init.php ➔ initTheme()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 71
rs 8.6327
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Flynt\Init;
4
5
require_once __DIR__ . '/Utils/FileLoader.php';
6
7
use Flynt;
8
use Flynt\Utils\Asset;
9
use Flynt\Utils\Feature;
10
use Flynt\Utils\FileLoader;
11
use Flynt\Utils\StringHelpers;
12
13
FileLoader::loadPhpFiles('lib/Utils');
14
15
function initTheme()
16
{
17
    // initialize plugin defaults
18
    Flynt\initDefaults();
19
20
    // Set to true to load all assets from a CDN if there is one specified
21
    Asset::loadFromCdn(false);
22
23
    // register all components in 'Components' folder
24
    add_theme_support('flynt-components', get_template_directory() . '/dist/Components/');
25
26
    // register all custom post types
27
    add_theme_support('flynt-custom-post-types', [
28
        'dir' => get_template_directory() . '/config/customPostTypes/',
29
        'fileName' => 'config.json'
30
    ]);
31
32
    // register all custom taxonomies
33
    add_theme_support('flynt-custom-taxonomies', [
34
        'dir' => get_template_directory() . '/config/customTaxonomies/'
35
    ]);
36
37
    // initialize ACF Field Groups and Option Pages
38
    add_theme_support('flynt-acf', [
39
        'FieldLoader',
40
        'FieldGroupComposer',
41
        'OptionPages',
42
        'FlexibleContentToggle',
43
        'GoogleMaps'
44
    ]);
45
46
    // enable admin notices
47
    add_theme_support('flynt-admin-notices');
48
49
    // set correct config dir (+ more?)
50
    add_theme_support('flynt-templates');
51
52
    // use timber rendering
53
    add_theme_support('flynt-timber-loader');
54
55
    // load jQuery in footer by default
56
    add_theme_support('flynt-jquery');
57
58
    // clean up some things
59
    add_theme_support('flynt-clean-head');
60
    add_theme_support('flynt-clean-rss');
61
    add_theme_support('flynt-mime-types');
62
    add_theme_support('flynt-navigation');
63
    add_theme_support('flynt-remove-editor');
64
    add_theme_support('flynt-tiny-mce');
65
66
    // add components previews
67
    add_theme_support('flynt-admin-component-preview');
68
69
    // google analytics
70
    add_theme_support('flynt-google-analytics');
71
72
    // hide protected posts
73
    add_theme_support('flynt-hide-protected-posts');
74
75
    // WP Stuff
76
    add_theme_support('title-tag');
77
    add_theme_support('post-thumbnails');
78
79
    add_theme_support('flynt-password-form');
80
    add_theme_support('flynt-external-script-loader');
81
    add_theme_support('flynt-lodash');
82
83
    // enable flynt log server
84
    add_theme_support('flynt-component-log-server');
85
}
86
add_action('after_setup_theme', __NAMESPACE__ . '\\initTheme');
87
88
function loadFeatures()
89
{
90
    $basePath = get_template_directory() . '/dist/Features';
91
92
    if (!is_dir($basePath)) {
93
        trigger_error(
94
            "Failed loading Features! {$basePath} does not exist! Did you run `flynt start` yet?",
95
            E_USER_WARNING
96
        );
97
        return;
98
    }
99
100
    // Filter out other (non-flynt) theme features
101
    $flyntThemeFeatures = array_filter($GLOBALS['_wp_theme_features'], function ($feature) {
102
        return StringHelpers::startsWith('flynt-', $feature);
103
    }, ARRAY_FILTER_USE_KEY);
104
105
    foreach ($flyntThemeFeatures as $feature => $options) {
106
        Feature::register($feature, $basePath, $options);
107
    }
108
109
    do_action('Flynt/afterRegisterFeatures');
110
}
111
add_action('after_setup_theme', __NAMESPACE__ . '\\loadFeatures', 100);
112