edulegit_submission_menu_builder::build()   B
last analyzed

Complexity

Conditions 7
Paths 32

Size

Total Lines 63
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 63
rs 8.223
cc 7
nc 32
nop 1

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
// 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
 * The assignsubmission_edulegit menu builder class.
19
 *
20
 * @package   assignsubmission_edulegit
21
 * @author    Alex Crosby <[email protected]>
22
 * @copyright @2024 EduLegit.com
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
26
namespace assignsubmission_edulegit;
27
28
/**
29
 * Class edulegit_submission_menu_builder
30
 *
31
 * Builds a menu for EduLegit submissions, providing options to view the submission in various formats.
32
 */
33
class edulegit_submission_menu_builder {
34
35
    /**
36
     * Builds the action menu for the given EduLegit submission.
37
     *
38
     * @param edulegit_submission_entity $edulegitsubmission The EduLegit submission entity to build the menu for.
39
     * @return \action_menu The built action menu.
40
     */
41
    public function build(edulegit_submission_entity $edulegitsubmission): \action_menu {
0 ignored issues
show
Bug introduced by
The type action_menu 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...
42
        $emptyicon = new \pix_icon('', '');
0 ignored issues
show
Bug introduced by
The type pix_icon 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...
43
44
        $menu = new \action_menu();
45
46
        $title = $edulegitsubmission->title ?: $this->translate('submission');
47
        $menu->actionicon = $emptyicon;
48
        $menu->actiontext = shorten_text($title, 32);
0 ignored issues
show
Bug introduced by
The function shorten_text was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $menu->actiontext = /** @scrutinizer ignore-call */ shorten_text($title, 32);
Loading history...
49
        $menu->set_action_label($title);
50
51
        $viewurl = $edulegitsubmission->get_view_url();
52
        if ($viewurl) {
53
            $menu->add(
54
                    new \action_menu_link(
0 ignored issues
show
Bug introduced by
The type action_menu_link 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...
55
                            new \moodle_url($viewurl),
0 ignored issues
show
Bug introduced by
The type moodle_url 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...
56
                            $emptyicon,
57
                            $this->translate('as_view'),
58
                            false
59
                    ));
60
        }
61
62
        $pdfurl = $edulegitsubmission->get_pdf_url();
63
        if ($pdfurl) {
64
            $menu->add(
65
                    new \action_menu_link(
66
                            new \moodle_url($pdfurl),
67
                            $emptyicon,
68
                            $this->translate('as_pdf'),
69
                            false
70
                    ));
71
        }
72
        $docxurl = $edulegitsubmission->get_docx_url();
73
        if ($docxurl) {
74
            $menu->add(
75
                    new \action_menu_link(
76
                            new \moodle_url($docxurl),
77
                            $emptyicon,
78
                            $this->translate('as_docx'),
79
                            false
80
                    ));
81
        }
82
        $htmlurl = $edulegitsubmission->get_html_url();
83
        if ($htmlurl) {
84
            $menu->add(
85
                    new \action_menu_link(
86
                            new \moodle_url($htmlurl),
87
                            $emptyicon,
88
                            $this->translate('as_html'),
89
                            false
90
                    ));
91
        }
92
        $txturl = $edulegitsubmission->get_txt_url();
93
        if ($txturl) {
94
            $menu->add(
95
                    new \action_menu_link(
96
                            new \moodle_url($txturl),
97
                            $emptyicon,
98
                            $this->translate('as_txt'),
99
                            false
100
                    ));
101
        }
102
103
        return $menu;
104
    }
105
106
    /**
107
     * Returns a localized string.
108
     *
109
     * @param string $identifier The key identifier for the localized string.
110
     * @return \lang_string|string The localized string.
0 ignored issues
show
Bug introduced by
The type lang_string 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...
111
     */
112
    private function translate(string $identifier) {
113
        return get_string($identifier, 'assignsubmission_edulegit');
0 ignored issues
show
Bug introduced by
The function get_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        return /** @scrutinizer ignore-call */ get_string($identifier, 'assignsubmission_edulegit');
Loading history...
114
    }
115
116
}
117