enrol_pagseguro_enrol_form   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 33
rs 10
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B definition() 0 30 1
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 29 and the first side effect is on line 25.

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
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * Pagseguro enrol plugin implementation.
19
 *
20
 * @package    enrol_pagseguro
21
 * @copyright  2015 Daniel Neis
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
25
defined('MOODLE_INTERNAL') || die();
26
27
require_once("$CFG->libdir/formslib.php");
28
29
class enrol_pagseguro_enrol_form extends moodleform {
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...
30
31
    public function definition() {
32
        $mform = $this->_form;
0 ignored issues
show
Unused Code introduced by
$mform is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
        $mform = $this->_form;
34
        $instance = $this->_customdata;
35
        $plugin = enrol_get_plugin('pagseguro');
36
37
        $heading = $plugin->get_instance_name($instance);
38
        $mform->addElement('header', 'pagseguroheader', $heading);
39
40
        $mform->addElement('static', 'paymentrequired', '', get_string('paymentrequired', 'enrol_pagseguro', $instance));
41
42
        $pagseguroimgurl = "https://p.simg.uol.com.br/out/pagseguro/i/botoes/pagamentos/99x61-pagar-assina.gif";
43
        $mform->addElement('static', 'paymentrequired', '',
44
                           html_writer::empty_tag('img', array('alt' => get_string('pagseguroaccepted', 'enrol_pagseguro'),
45
                                                               'src' => $pagseguroimgurl)));
46
47
        $mform->addElement('hidden', 'courseid', $instance->courseid);
48
        $mform->setType('courseid', PARAM_INT);
49
50
        $mform->addElement('hidden', 'instanceid', $instance->id);
51
        $mform->setType('instanceid', PARAM_INT);
52
53
        $mform->addElement('hidden', 'cost', $instance->cost);
54
        $mform->setType('cost', PARAM_INT);
55
56
        $mform->addElement('hidden', 'usersubmitted', 1);
57
        $mform->setType('usersubmitted', PARAM_INT);
58
59
        $this->add_action_buttons(false, get_string('sendpaymentbutton', 'enrol_pagseguro'), '1');
60
    }
61
}
62