Issues (4)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

components/TimeToRead.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace GinoPane\BlogTimeToRead\Components;
4
5
use RainLab\Blog\Models\Post;
6
use Cms\Classes\ComponentBase;
7
use GinoPane\BlogTimeToRead\Plugin;
8
use GinoPane\BlogTimeToRead\Models\Settings;
9
use GinoPane\BlogTimeToRead\Helpers\TimeToRead as TimeToReadHelper;
10
11
12
/**
13
 * Class TimeToRead
14
 *
15
 * @package GinoPane\BlogTaxonomy\Components
16
 */
17
class TimeToRead extends ComponentBase
18
{
19
    const NAME = 'timeToRead';
20
21
    /**
22
     * @var int
23
     */
24
    private $readingSpeed;
25
26
    /**
27
     * @var bool
28
     */
29
    private $isRoundingUpEnabled;
30
31
    /**
32
     * @var string
33
     */
34
    private $postSlug;
35
36
    /**
37
     * @var int
38
     */
39
    public $minutes;
40
41
    /**
42
     * Returns information about this component, including name and description.
43
     */
44
    public function componentDetails()
45
    {
46
        return [
47
            'name'        => Plugin::LOCALIZATION_KEY . 'components.timetoread.name',
48
            'description' => Plugin::LOCALIZATION_KEY . 'components.timetoread.description'
49
        ];
50
    }
51
52
    /**
53
     * Component Properties
54
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,array<string,string|false>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
55
     */
56
    public function defineProperties()
57
    {
58
        return [
59
            'postSlug' => [
60
                'title'       => Plugin::LOCALIZATION_KEY . 'components.timetoread.post_slug_title',
61
                'description' => Plugin::LOCALIZATION_KEY . 'components.timetoread.post_slug_description',
62
                'default'     => '{{ :slug }}',
63
                'type'        => 'string'
64
            ],
65
66
            'readingSpeed' => [
67
                'title'         => Plugin::LOCALIZATION_KEY . 'settings.default_reading_speed',
68
                'description'   => Plugin::LOCALIZATION_KEY . 'settings.default_reading_speed_comment',
69
                'default'       => Settings::DEFAULT_READING_SPEED,
70
                'type'          => 'string',
71
                'validationPattern' => '^(0+)?[1-9]\d*$',
72
                'showExternalParam' => false
73
            ],
74
75
            'isRoundingUpEnabled' => [
76
                'title'       =>    Plugin::LOCALIZATION_KEY . 'settings.rounding_up_enabled',
77
                'description' =>    Plugin::LOCALIZATION_KEY . 'settings.rounding_up_enabled_comment',
78
                'type'        =>    'checkbox',
79
                'default'     =>    Settings::DEFAULT_ROUNDING_UP_ENABLED,
80
                'showExternalParam' => false
81
            ],
82
        ];
83
    }
84
85
    /**
86
     * Query the tag and posts belonging to it
87
     */
88
    public function onRun()
89
    {
90
        $this->prepareVars();
91
92
        $this->calculateReadingTime();
93
    }
94
95
    /**
96
     * Prepare variables
97
     *
98
     * @return void
99
     */
100
    private function prepareVars()
101
    {
102
        $this->postSlug = (string)$this->property('postSlug');
103
        $this->readingSpeed = (int)$this->property('readingSpeed');
104
        $this->isRoundingUpEnabled = (bool)$this->property('isRoundingUpEnabled');
105
    }
106
107
    /**
108
     * @return void
109
     */
110
    private function calculateReadingTime()
111
    {
112
        $post = Post::whereSlug($this->postSlug)->first();
113
114
        if (!$post) {
115
            $this->minutes = 0;
116
            return;
117
        }
118
119
        $this->minutes = TimeToReadHelper::get()->calculate(
120
            $post->content,
121
            array_filter([
122
                Settings::READING_SPEED_KEY => $this->readingSpeed,
123
                Settings::ROUNDING_UP_ENABLED_KEY => $this->isRoundingUpEnabled
124
            ])
125
        );
126
    }
127
}
128