GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 9e9d51...fc7292 )
by Borut
03:13
created

EmailController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 16.13 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 5
dl 15
loc 93
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 15 15 2
B previewTemplatesAction() 0 62 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Application\Controller\MembersArea\Tools;
4
5
use Application\Tool\Helpers;
6
use Silex\Application;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
10
/**
11
 * @author Borut Balažek <[email protected]>
12
 */
13
class EmailController
14
{
15
    /**
16
     * @param Request     $request
17
     * @param Application $app
18
     *
19
     * @return Response
20
     */
21 View Code Duplication
    public function indexAction(Request $request, Application $app)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method 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...
22
    {
23
        $data = array();
24
25
        if (!$app['security']->isGranted('ROLE_ADMIN')) {
26
            $app->abort(403);
27
        }
28
29
        return new Response(
30
            $app['twig']->render(
31
                'contents/members-area/tools/email.html.twig',
32
                $data
33
            )
34
        );
35
    }
36
37
    /**
38
     * @param Request     $request
39
     * @param Application $app
40
     *
41
     * @return Response
42
     */
43
    public function previewTemplatesAction(Request $request, Application $app)
44
    {
45
        if (!$app['security']->isGranted('ROLE_ADMIN')) {
46
            $app->abort(403);
47
        }
48
49
        $data = array();
50
51
        $templates = array();
52
        $template = $request->query->get('template', false);
53
        $raw = $request->query->has('raw');
54
55
        // Set some possible global defaults for the template
56
        $emailData = array(
57
            'app' => $app,
58
            'user' => $app['user'],
59
            'content' => 'Hello world!',
60
            'formData' => array(
61
                'message' => 'Just a test message!',
62
            ),
63
        );
64
65
        if ($template && $raw) {
66
            $app['debug'] = false;
67
            $app['showProfiler'] = false;
68
69
            return $app['mailer.css_to_inline_styles_converter'](
70
                'emails/'.$template.'.html.twig',
71
                $emailData
72
            );
73
        }
74
75
        $templatesArray = Helpers::rglob(
76
            APP_DIR.'/templates/emails/*.html.twig'
77
        );
78
79
        if ($templatesArray) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $templatesArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
80
            foreach ($templatesArray as $templatePath) {
81
                $templatePath = str_replace(
82
                    APP_DIR.'/templates/emails/',
83
                    '',
84
                    $templatePath
85
                );
86
87
                $templates[] = str_replace(
88
                    '.html.twig',
89
                    '',
90
                    $templatePath
91
                );
92
            }
93
        }
94
95
        $data['template'] = $template;
96
        $data['templates'] = $templates;
97
98
        return new Response(
99
            $app['twig']->render(
100
                'contents/members-area/tools/email/preview-templates.html.twig',
101
                $data
102
            )
103
        );
104
    }
105
}
106