Issues (222)

Security Analysis    not enabled

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

src/Billing/Plan/BillaBearPlanManager.php (6 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\Billing\Plan;
23
24
use BillaBear\Model\Feature;
0 ignored issues
show
The type BillaBear\Model\Feature 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...
25
use BillaBear\Model\Limit;
0 ignored issues
show
The type BillaBear\Model\Limit 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...
26
use BillaBear\Model\Price;
0 ignored issues
show
The type BillaBear\Model\Price 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...
27
use BillaBear\Model\SubscriptionPlan;
0 ignored issues
show
The type BillaBear\Model\SubscriptionPlan 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...
28
use Doctrine\Common\Collections\Collection;
29
use Parthenon\Billing\BillaBear\SdkFactory;
30
use Parthenon\Billing\Exception\NoPlanFoundException;
31
32
final class BillaBearPlanManager implements PlanManagerInterface
33
{
34
    private ?array $plans = null;
35
36
    public function __construct(
37
        private SdkFactory $sdkFactory,
38
    ) {
39
    }
40
41
    public function getPlans(): array
42
    {
43
        if (!isset($this->plans)) {
44
            $data = $this->sdkFactory->createSubscriptionsApi()->listSubscriptionPlans(limit: 100);
45
46
            $output = [];
47
            foreach ($data->getData() as $planEntity) {
48
                $output[] = $this->convertPlan($planEntity);
49
            }
50
            $this->plans = $output;
51
        }
52
53
        return $output;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $output does not seem to be defined for all execution paths leading up to this point.
Loading history...
54
    }
55
56
    public function getPlanForUser(LimitedUserInterface $limitedUser): Plan
57
    {
58
        return $this->getPlanByName($limitedUser->getPlanName());
0 ignored issues
show
It seems like $limitedUser->getPlanName() can also be of type null; however, parameter $planName of Parthenon\Billing\Plan\B...anager::getPlanByName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

58
        return $this->getPlanByName(/** @scrutinizer ignore-type */ $limitedUser->getPlanName());
Loading history...
59
    }
60
61
    public function getPlanByName(string $planName): Plan
62
    {
63
        $plans = $this->getPlans();
64
65
        foreach ($plans as $plan) {
66
            if ($plan->getName() === $planName) {
67
                return $plan;
68
            }
69
        }
70
        throw new NoPlanFoundException();
71
    }
72
73
    protected function convertPlan(SubscriptionPlan $subscriptionPlan): Plan
74
    {
75
        return new Plan(
76
            $subscriptionPlan->getName(),
77
            $this->convertLimits($subscriptionPlan->getLimits()),
78
            $this->convertFeatures($subscriptionPlan->getFeatures()),
79
            $this->convertPrices($subscriptionPlan->getPrices()),
80
            $subscriptionPlan->getFree(),
81
            $subscriptionPlan->getPerSeat(),
82
            $subscriptionPlan->getUserCount(),
83
            $subscriptionPlan->getPublic(),
84
            $subscriptionPlan->getHasTrial(),
85
            $subscriptionPlan->getTrialLengthDays(),
86
            $subscriptionPlan->getId()
87
        );
88
    }
89
90
    /**
91
     * @param Limit[] $limits
92
     */
93
    protected function convertLimits(array $limits): array
94
    {
95
        $output = [];
96
97
        foreach ($limits as $limit) {
98
            $output[$limit->getFeature()->getCode()] = [
99
                'name' => $limit->getFeature()->getName(),
100
                'code' => $limit->getFeature()->getCode(),
101
                'limit' => $limit->getLimit(),
102
                'description' => $limit->getFeature()->getDescription(),
103
            ];
104
        }
105
106
        return $output;
107
    }
108
109
    /**
110
     * @param Feature[]|Collection $features
111
     */
112
    protected function convertFeatures(array $features): array
113
    {
114
        $output = [];
115
116
        foreach ($features as $feature) {
117
            $output[$feature->getCode()] = [
118
                'code' => $feature->getCode(),
119
                'name' => $feature->getName(),
120
                'description' => $feature->getDescription(),
121
            ];
122
        }
123
124
        return $output;
125
    }
126
127
    /**
128
     * @param Price[]|Collection $prices
129
     */
130
    protected function convertPrices(array $prices): array
131
    {
132
        $output = [];
133
134
        foreach ($prices as $price) {
135
            $schedule = $price->getSchedule();
136
137
            if (!isset($output[$schedule])) {
138
                $output[$schedule] = [];
139
            }
140
141
            $output[$schedule][$price->getCurrency()] = [
142
                'amount' => (string) $price->getAmount(),
143
                'currency' => $price->getCurrency(),
144
                'price_id' => $price->getExternalReference(),
145
                'public' => $price->getPublic(),
146
                'entity_id' => $price->getId(),
147
            ];
148
        }
149
150
        return $output;
151
    }
152
}
153