Issues (4)

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/Drivers/MyQuran.php (1 issue)

1
<?php
2
3
namespace Ianrizky\MoslemPray\Drivers;
4
5
use Exception;
6
use Ianrizky\MoslemPray\Contracts\Response\HasPrayerTime;
7
use Ianrizky\MoslemPray\Contracts\Response\HasPrayerTimeCollection;
8
use Ianrizky\MoslemPray\Response\MyQuran\City;
9
use Ianrizky\MoslemPray\Response\MyQuran\Collection\CityCollection;
10
use Ianrizky\MoslemPray\Response\MyQuran\Collection\PrayerTimeCollection;
11
use Ianrizky\MoslemPray\Response\MyQuran\Collection\TafsirCollection;
12
use Ianrizky\MoslemPray\Response\MyQuran\PrayerTime;
13
use Ianrizky\MoslemPray\Support\ParseDate;
14
use Illuminate\Http\Client\Response;
15
16
/**
17
 * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS
18
 */
19
class MyQuran extends AbstractDriver
20
{
21 1
    use ParseDate;
22
23
    /**
24
     * List of configuration value.
25
     *
26
     * @var array
27
     */
28
    protected $config = [
29
        'url' => 'https://api.myquran.com/v1/',
30
    ];
31
32
    /**
33
     * Return city information based on the given identifier.
34
     *
35
     * @param  mixed  $identifier
36
     * @return \Ianrizky\MoslemPray\Response\MyQuran\City
37
     */
38 6
    public function getCity($identifier): City
39
    {
40 6
        if (is_numeric($identifier)) {
41 2
            return $this->getCityFromId($identifier);
42
        }
43
44 4
        return $this->getCityFromName($identifier);
45
    }
46
47
    /**
48
     * Return city information based on the given id.
49
     *
50
     * @param  mixed  $id
51
     * @return \Ianrizky\MoslemPray\Response\MyQuran\City
52
     *
53
     * @see https://api.myquran.com/v1/sholat/kota/id/{id}
54
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#88549bc5-cd70-4ba1-b565-f3eef882e060 (Sholat/Lokasi/ID Kota)
55
     */
56 4
    public function getCityFromId($id): City
57
    {
58 4
        $response = $this->throwJsonError(
59 4
            $this->request->get('/sholat/kota/id/' . $id)
60
        );
61
62 2
        return new City([
63 2
            'id' => data_get($response->json(), 'data.id'),
64 2
            'name' => data_get($response->json(), 'data.lokasi'),
65
        ]);
66
    }
67
68
    /**
69
     * Return city information based on the given name.
70
     *
71
     * @param  string  $name
72
     * @return \Ianrizky\MoslemPray\Response\MyQuran\City
73
     *
74
     * @see https://api.myquran.com/v1/sholat/kota/cari/{name}
75
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#ae4b237c-e97c-4353-9e94-67d155af06f8 (Sholat/Lokasi/Pencarian)
76
     */
77 6
    public function getCityFromName(string $name): City
78
    {
79 6
        $response = $this->throwJsonError(
80 6
            $this->request->get('/sholat/kota/cari/' . $name)
81
        );
82
83 4
        return new City([
84 4
            'id' => data_get($response->json(), 'data.0.id'),
85 4
            'name' => data_get($response->json(), 'data.0.lokasi'),
86
        ]);
87
    }
88
89
    /**
90
     * Return list of all city.
91
     *
92
     * @return \Ianrizky\MoslemPray\Response\MyQuran\Collection\CityCollection
93
     *
94
     * @see https://api.myquran.com/v1/sholat/kota/semua
95
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#145bcb30-dba6-4d24-9799-03ba878b5476 (Sholat/Lokasi/Semua Kota)
96
     */
97 1
    public function getCities(): CityCollection
98
    {
99 1
        $response = $this->throwJsonError(
100 1
            $this->request->get('/sholat/kota/semua')
101
        );
102
103 1
        return new CityCollection(array_map(function ($data) {
104
            return [
105 1
                'id' => $data['id'],
106 1
                'name' => $data['lokasi'],
107
            ];
108 1
        }, $response->json()));
109
    }
110
111
    /**
112
     * {@inheritDoc}
113
     *
114
     * @return \Ianrizky\MoslemPray\Response\MyQuran\PrayerTime
115
     *
116
     * @see https://api.myquran.com/v1/sholat/jadwal/{city_id}/{year}/{month}/{date}
117
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#534da562-3335-4a1f-bca2-d7ee2266f457 (Sholat/Jadwal/Per Hari)
118
     */
119 1
    public function getPrayerTime($city, $date = null): HasPrayerTime
120
    {
121 1
        $city = $this->getCity($city);
122 1
        $date = $this->parseDate($date);
123
124 1
        $response = $this->throwJsonError(
125 1
            $this->request->get(sprintf('/sholat/jadwal/%s/%s', $city->id, $date->format('Y/m/d')))
126
        );
127
128 1
        return PrayerTime::fromResponse($response);
129
    }
130
131
    /**
132
     * {@inheritDoc}
133
     *
134
     * @return \Ianrizky\MoslemPray\Response\MyQuran\Collection\PrayerTimeCollection
135
     *
136
     * @see https://api.myquran.com/v1/sholat/jadwal/{city_id}/{year}/{month}
137
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#b0b39104-8216-49fc-9d3b-ea53e5832e16 (Sholat/Jadwal/Per Bulan)
138
     */
139 1
    public function getPrayerTimePerMonth($city, $year = null, int $month = null): HasPrayerTimeCollection
140
    {
141 1
        $city = $this->getCity($city);
142
143 1
        if ($year && $month) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $month of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
144
            $date = $this->parseDate($year . '-' . $month . '-1');
145
        } else {
146 1
            $date = $this->parseDate($year);
147
        }
148
149 1
        $response = $this->throwJsonError(
150 1
            $this->request->get(sprintf('/sholat/jadwal/%s/%s', $city->id, $date->format('Y/m')))
151
        );
152
153 1
        return PrayerTimeCollection::fromResponse($response);
154
    }
155
156
    /**
157
     * Return list of tafsir based on the given ayat number.
158
     *
159
     * @param  int  $ayat
160
     * @return \Ianrizky\MoslemPray\Response\MyQuran\Collection\TafsirCollection
161
     *
162
     * @see https://api.myquran.com/v1/tafsir/quran/kemenag/id/{id}
163
     * @see https://documenter.getpostman.com/view/841292/Tz5p7yHS#9065c3f0-23b7-48b6-884a-a28da0826e03 (Tafsir/alQuran/Kemenag/id)
164
     */
165 1
    public function getTafsir(int $ayat): TafsirCollection
166
    {
167 1
        $response = $this->throwJsonError(
168 1
            $this->request->get('/tafsir/quran/kemenag/id/' . $ayat)
169
        );
170
171 1
        return TafsirCollection::fromResponse($response);
172
    }
173
174
    /**
175
     * {@inheritDoc}
176
     */
177 12
    protected function throwJsonError(Response $response): Response
178
    {
179 12
        $status = data_get($response->json(), 'status', true);
180 12
        $message = data_get($response->json(), 'message', 'MyQuran API error');
181
182 12
        if (!$status) {
183 4
            throw new Exception($message);
184
        }
185
186 8
        return $response;
187
    }
188
}
189