Issues (2)

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.

src/PersonName.php (2 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
namespace Druc\PersonName;
4
5
class PersonName
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
6
{
7
    /** @var string */
8
    public $fullName;
9
10
    /**
11
     * PersonName constructor.
12
     * @param string $fullName
13
     */
14 30
    private function __construct(string $fullName = '')
15
    {
16 30
        $this->fullName = $fullName;
17 30
    }
18
19
    /**
20
     * @param string $fullName
21
     * @return PersonName
22
     */
23 30
    public static function make(string $fullName)
24
    {
25 30
        return new static($fullName);
26
    }
27
28
    /**
29
     * @param $property
30
     * @return null
31
     */
32 30
    public function __get($property)
33
    {
34 30
        if (in_array($property, get_class_methods($this))) {
35 30
            return $this->{$property}();
36
        }
37
38
        return null;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 3
    public function full()
45
    {
46 3
        return $this->fullName;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 15
    public function first()
53
    {
54 15
        return preg_split('/\s+/', $this->fullName, 2)[0];
55
    }
56
57
    /**
58
     * @return string
59
     */
60 21
    public function last()
61
    {
62 21
        return preg_split('/\s+/', $this->fullName, 2)[1];
63
    }
64
65
    /**
66
     * @return string
67
     */
68 3
    public function initials()
69
    {
70 3
        preg_match_all('/\b(\S)\S*/', $this->fullName, $matches);
71 3
        return implode('', $matches[1]);
72
    }
73
74
    /**
75
     * First name + Last name initial
76
     * Ex: Constantin Druc Pinsmile -> Constantin D.
77
     * @return string
78
     */
79 6
    public function familiar()
80
    {
81 6
        return $this->first() . ' ' . substr($this->last(), 0, 1) . '.';
82
    }
83
84
    /**
85
     * Ex: Constantin Druc Pinsmile -> CDP
86
     * @return string
87
     */
88 3
    public function abbreviated()
89
    {
90 3
        return substr($this->first, 0, 1) . '. ' . $this->last();
0 ignored issues
show
The property first does not exist on object<Druc\PersonName\PersonName>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
91
    }
92
93
    /**
94
     * Last name, First name
95
     * Ex: Constantin Druc Pinsmile -> Druc Pinsmile, Constantin
96
     * @return string
97
     */
98 3
    public function sorted()
99
    {
100 3
        return $this->last() . ', ' . $this->first();
101
    }
102
103
    /**
104
     * Lowercase and whitespace striped version of the familiar name
105
     * @return string
106
     */
107 3
    public function mentionable()
108
    {
109 3
        return rtrim(strtolower(preg_replace('/\s+/', '', $this->familiar())), ". ");
110
    }
111
112
    /**
113
     * @return string
114
     */
115 6
    public function possessive()
116
    {
117 6
        if (substr($this->last(), -1, 1) !== 's') {
118 3
            return $this->fullName . "'s";
119
        }
120
121 3
        return $this->fullName . "'";
122
    }
123
}
124