Issues (76)

Security Analysis    not enabled

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.

src/functions.php (3 issues)

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
/**
4
 * Mastodon API functions
5
 *
6
 * @author    USAMI Kenta <[email protected]>
7
 * @copyright 2017 Baguette HQ
8
 * @license   https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0
9
 */
10
11
namespace Baguette\Mastodon;
12
13
use Baguette\Mastodon\Grant;
14
use Baguette\Mastodon\Service;
15
use Baguette\Mastodon\Service\Scope;
16
17
/**
18
 * @param  string   $instance
19
 * @param  string   $client_id
20
 * @param  string   $client_secret
21
 * @param  array    $options
22
 * @return Mastodon
23
 */
24
function session($instance, $client_id, $client_secret, array $options)
25
{
26 1
    $scope = null;
27 1
    $grant = null;
28 1
    $authorization = null;
29
30 1
    $client = new Client($instance);
31
32 1
    if (isset($options['scope'])) {
33 1
        $scope = scope($options['scope']);
34
    }
35
36 1
    if (isset($options['credential'])) {
37
        trigger_error('`credential` is obsolete option.  Use `grant` instead.', E_USER_DEPRECATED);
38
        $grant = credential($options['credential']);
39
    }
40
41 1
    if (isset($options['grant'])) {
42 1
        $grant = grant($options['grant']);
43
    }
44
45 1
    if (isset($options['authorization'])) {
46 1
        $authorization = authorization($options['authorization']);
47
    }
48
49
    //throw new \LogicException('"scope" is not set.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
51 1
    $auth_factory = new Service\AuthFactory($client, $client_id, $client_secret);
52 1
    if ($grant !== null) {
53 1
        $auth_factory->setGrant($grant);
54
    }
55
56 1
    $session = new Service\SessionStorage($auth_factory, $scope);
57 1
    if ($authorization !== null) {
58 1
        $session->setAuthorization($authorization);
59
    }
60
61 1
    return new Mastodon($client, $session);
62
}
63
64
/**
65
 * @param  Scope|string|string[]
66
 * @return Scope
67
 */
68
function scope($scope)
69
{
70 6
    if (is_array($scope)) {
71 1
        return new Scope($scope);
72
    } elseif ($scope instanceof Scope) {
73 1
        return $scope;
74
    }
75
76 4
    return new Scope(explode(' ', $scope));
77
}
78
79
/**
80
 * @param  string $toot_string
81
 * @param  array  $options
82
 * @return Service\Toot
83
 */
84
function toot($toot_string, array $options = [])
85
{
86 1
    return new Service\Toot($toot_string, $options);
87
}
88
89
/**
90
 * @deprecated
91
 */
92
function credential(array $data)
93
{
94
    trigger_error('credential() is obsolete function.  Use grant() instead.', E_USER_DEPRECATED);
95
    return grant($data);
96
}
97
98
/**
99
 * @return Grant\Grant
100
 */
101
function grant(array $data)
102
{
103 5
    if (isset($data['username'], $data['password'])) {
104 5
        return new Grant\PasswordCredential($data['username'], $data['password']);
105
    }
106
}
107
108
/**
109
 * @return Service\Authorization
110
 */
111
function authorization(array $data)
112
{
113 1
    return Service\Authorization::fromObject((object)$data);
114
}
115
116
/**
117
 * @return \GuzzleHttp\ClientInterface
118
 */
119
function http(\GuzzleHttp\ClientInterface $client = null)
120
{
121
    /** @var \GuzzleHttp\ClientInterface */
122 1
    static $cached_client;
123
124 1
    if ($client !== null) {
125
        $cached_client = $client;
126 1
    } elseif ($cached_client === null) {
127 1
        $cached_client = new \GuzzleHttp\Client;
128
    }
129
130 1
    return $cached_client;
131
}
132
133
/**
134
 * Manually API Request
135
 *
136
 * @param  Mastodon        $service A instance object of Mastodon class
137
 * @param  string          $method  HTTP Method (GET, POST, PUT, DELETE, ...)
138
 * @param  string          $path    API Path (URL)
139
 * @param  array           $options Options for GuzzleHttp
140
 * @param  string|string[] $class   A class name of return value
141
 * @return \Psr\Http\Message\ResponseInterface|Entity\Entity|Entity\Entity[]|mixed Returns ResponseInterface if $class is NULL.
142
 */
143
function request(Mastodon $service, $method, $path, $options, $class = null)
144
{
145
    $response = $service->client->requestAPI($method, $path, $options, $service->session);
0 ignored issues
show
The property $client is declared private in Baguette\Mastodon\Mastodon. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property $session is declared private in Baguette\Mastodon\Mastodon. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
146
147
    if ($class === null) {
148
        return $response;
149
    }
150
151
    return Entity\map($class, \GuzzleHttp\json_decode($response->getBody(), true));
152
}
153