Issues (100)

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/utils/PersonGenerator.php (7 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
 * PersonGenerator
4
 *
5
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6
 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7
 *
8
 * Permission is hereby granted to use or copy this program
9
 * for any purpose, provided the above notices are retained on all copies.
10
 * Permission to modify the code and to distribute modified code is granted,
11
 * provided the above notices are retained, and a notice that the code was
12
 * modified is included with the above copyright notice.
13
 *
14
 * @category  Wp
15
 * @package   Punction
16
 * @author    Andrzej Marcinkowski <[email protected]>
17
 * @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz
18
 * @license   MIT http://opensource.org/licenses/MIT
19
 * @version   1.0 $Id: a88997670673063e272ee5666aa86ed1ec9a1561 $ $Format:%H$
20
 * @link      http://
21
 * @since     File available since Release 1.0.0
22
 * PHP Version 5
23
 */
24
namespace Hospitalplugin\utils;
25
26
use Hospitalplugin\Entities\Patient;
27
use Hospitalplugin\Entities\PatientZZ;
28
29
/**
30
 * PersonGenerator
31
 *
32
 * @category  Wp
33
 * @package   Punction
34
 * @author    Andrzej Marcinkowski <[email protected]>
35
 * @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz
36
 * @license   MIT http://opensource.org/licenses/MIT
37
 * @version   1.0 $Id: a88997670673063e272ee5666aa86ed1ec9a1561 $ $Format:%H$
38
 * @link      http://
39
 * @since     File available since Release 1.0.0
40
 *
41
 */
42
class PersonGenerator
43
{
44
45
    private static $names;
46
47
    private static $mnames;
48
49
    private static $fnames;
50
51
    /**
52
     * @return \Hospitalplugin\Entities\Patient
53
	 */
54
    public static function getRandomPerson()
55
    {
56
        // TODO extract paths
57
        self::$names = Utils::readFileToArray(__DIR__ . '/../../resources/pl_names.csv');
58
        self::$mnames = Utils::readFileToArray(__DIR__ . '/../../resources/pl_mnames.csv');
59
        self::$fnames = Utils::readFileToArray(__DIR__ . '/../../resources/pl_fnames.csv');
60
        // var_dump(self::$mnames);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
61
        $sex = (rand(0, 1) == 0 ? 'm' : 'f');
62
        $firstname = ($sex == 'm' ? self::getRandom(self::$mnames) : self::getRandom(self::$fnames));
0 ignored issues
show
self::$mnames is of type array, but the function expects a object<Hospitalplugin\utils\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
self::$fnames is of type array, but the function expects a object<Hospitalplugin\utils\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        $lastname = self::getRandom(self::$names);
0 ignored issues
show
self::$names is of type array, but the function expects a object<Hospitalplugin\utils\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
        if ($sex == 'f' && self::endsWith($lastname, 'i')) {
0 ignored issues
show
$lastname is of type string, but the function expects a object<Hospitalplugin\utils\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'i' is of type string, but the function expects a object<Hospitalplugin\utils\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
            $lastname = rtrim($lastname, "i") . 'a';
66
        }
67
        $bdate = self::getRandomBirthDate();
68
        $pesel = self::getRandomPesel($bdate, $sex);
69
        return $firstname . ' ' . $lastname . '|' . $pesel;
70
    }
71
72
    /**
73
     * @param unknown $haystack
74
     * @param unknown $needle
75
     * @return boolean
76
     */
77
    static function endsWith($haystack, $needle)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
78
    {
79
        return $needle === "" || substr($haystack, - strlen($needle)) === $needle;
80
    }
81
82
    /**
83
     * @return random date 
84
     */
85
    public static function getRandomBirthDate()
86
    {
87
        $age = rand(0, 100);
88
        $dayOfYear = rand(0, 365);
89
        $interval = new \DateInterval('P' . $age . 'Y' . $dayOfYear . 'D');
90
        $date = new \DateTime();
91
        $birth = $date->sub($interval);
92
        return $birth->format('Y-m-d');
93
    }
94
95
    /**
96
	 *
97
	 * @param $date        	
98
	 * @param $sex
99
	 *        	'm' / 'f'
100
	 */
101
    public static function getRandomPesel($date, $sex = 'm')
102
    {
103
        $datetime = new \DateTime($date);
104
        $y = (int) $datetime->format('y');
105
        $Y = (int) $datetime->format('Y');
106
        $m = (int) $datetime->format('m');
107
        $d = (int) $datetime->format('d');
108
        if ($Y >= 2000) {
109
            $m += 20;
110
        }
111
        $sexNum = ($sex == 'f' ? rand(0, 4) * 2 : rand(0, 4) * 2 + 1);
112
        $x = sprintf('%02d%02d%02d%03d%d', $y, $m, $d, rand(0, 999), $sexNum);
113
        $arrSteps = array(
114
            1,
115
            3,
116
            7,
117
            9,
118
            1,
119
            3,
120
            7,
121
            9,
122
            1,
123
            3
124
        ); // tablica z odpowiednimi wagami
125
        $intSum = 0;
126
        for ($i = 0; $i < 10; $i ++) {
127
            $intSum += $arrSteps[$i] * $x[$i]; // mnożymy każdy ze znaków
128
                                                   // przez wagć i sumujemy
129
                                                   // wszystko
130
        }
131
        $int = 10 - $intSum % 10; // obliczamy sumć kontrolną
132
        $intControlNr = ($int == 10) ? 0 : $int;
133
        $x .= $intControlNr;
134
        return $x;
135
    }
136
137
    /**
138
     * random element frmo array
139
     * 
140
     * @param unknown $arr
141
     * @return string random element
142
	 */
143
    public static function getRandom($arr)
144
    {
145
        return implode('', $arr[array_rand($arr)]);
146
    }
147
}
148
149