Skip to content

Commit 24e3843

Browse files
committed
Methods changed to typed
1 parent 33b0eee commit 24e3843

File tree

11 files changed

+68
-98
lines changed

11 files changed

+68
-98
lines changed

berry/encryption.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
2+
23
require_once(__DIR__ . "/encryption/AES128Encryption.php");
34
?>

berry/encryption/AES128Encryption.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
<?php
22

3-
/*
4-
MIT License
5-
6-
Copyright (c) 2022 Nikos Siatras
7-
8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all
16-
copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24-
SOFTWARE.
25-
*/
26-
273
class AES128Encryption
284
{
295

306
private static string $OPENSSL_CIPHER_NAME = "aes-128-cbc"; //Name of OpenSSL Cipher
317
private static int $CIPHER_KEY_LEN = 16; // 16 bytes (128 bits)
328

33-
static function getRandomIV()
9+
static function getRandomIV(): string
3410
{
3511
$characters = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()-=_+ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3612
$charactersLength = strlen($characters);
@@ -50,7 +26,7 @@ static function getRandomIV()
5026
* @param type $data - data to encrypt
5127
* @return encrypted data in base64 encoding with iv attached at end after a :
5228
*/
53-
static function encrypt(string $key, string $data)
29+
static function encrypt(string $key, string $data): string
5430
{
5531
$iv = AES128Encryption::getRandomIV();
5632

@@ -75,7 +51,7 @@ static function encrypt(string $key, string $data)
7551
* @param type $data - data to be decrypted in base64 encoding with iv attached at the end after a :
7652
* @return decrypted data
7753
*/
78-
static function decrypt(string $key, string $data)
54+
static function decrypt(string $key, string $data): string
7955
{
8056
if (strlen($key) < AES128Encryption::$CIPHER_KEY_LEN)
8157
{
@@ -90,6 +66,7 @@ static function decrypt(string $key, string $data)
9066
$decryptedData = openssl_decrypt(base64_decode($parts[0]), AES128Encryption::$OPENSSL_CIPHER_NAME, $key, OPENSSL_RAW_DATA, base64_decode($parts[1]));
9167
return $decryptedData;
9268
}
69+
9370
}
9471

9572
?>

berry/mysql/MySQLCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
class MySQLCommand
44
{
55

6-
private MySQLConnection $fMySQLConnection; // MySQLConnection of this command
7-
private String $fQuery; // Query to execute
8-
private $fPreparedStatement = NULL; // The prepared statement of this command
9-
public MySQLCommandParameters $Parameters; // Command parameters
6+
private MySQLConnection $fMySQLConnection; // MySQLConnection of this command
7+
private String $fQuery; // Query to execute
8+
private $fPreparedStatement = NULL; // The prepared statement of this command
9+
public MySQLCommandParameters $Parameters; // Command parameters
1010

1111
/**
1212
* Constructs a new MySQLCommand
@@ -24,7 +24,7 @@ public function __construct(MySQLConnection $mySQLConnection, String $query = ""
2424
* Execute query and return the number of affected rows.
2525
* @return the number of affected rows.
2626
*/
27-
public function ExecuteQuery()
27+
public function ExecuteQuery(): int
2828
{
2929
if (sizeof($this->Parameters->getParameters()) > 0) // Query with parameters (Prepared Statement)
3030
{
@@ -67,7 +67,7 @@ public function ExecuteQuery()
6767
* Returns MySQLDataReader
6868
* @return MySQLDataReader
6969
*/
70-
public function ExecuteReader()
70+
public function ExecuteReader(): MySQLDataReader
7171
{
7272
$this->fPreparedStatement = NULL;
7373

@@ -110,7 +110,7 @@ public function ExecuteReader()
110110
* $query: is the query to set
111111
* @param type $query
112112
*/
113-
public function setQuery($query)
113+
public function setQuery($query): void
114114
{
115115
$this->fQuery = $query;
116116
}
@@ -119,7 +119,7 @@ public function setQuery($query)
119119
* Return's the query been given to this command
120120
* @return string the command's query
121121
*/
122-
public function getQuery()
122+
public function getQuery(): string
123123
{
124124
return $this->fQuery;
125125
}
@@ -128,7 +128,7 @@ public function getQuery()
128128
* Returns the MySQLConnection of this MySQLCommand
129129
* @return type MySQLConnection
130130
*/
131-
public function getMySQLConnection()
131+
public function getMySQLConnection(): MySQLConnection
132132
{
133133
return $this->fMySQLConnection;
134134
}
@@ -137,7 +137,7 @@ public function getMySQLConnection()
137137
* Return's the last inserted ID
138138
* @return type
139139
*/
140-
public function getLastInsertID()
140+
public function getLastInsertID(): int
141141
{
142142
return $this->fMySQLConnection->getLink()->insert_id;
143143
}
@@ -147,7 +147,7 @@ public function getLastInsertID()
147147
* This method should be called every time before query execution.
148148
* @return type
149149
*/
150-
private function BindParametersToQuery()
150+
private function BindParametersToQuery(): void
151151
{
152152
$parameterTypes = "";
153153
$ar = array();
@@ -168,4 +168,4 @@ private function BindParametersToQuery()
168168

169169
}
170170

171-
?>
171+
?>

berry/mysql/MySQLCommandParameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class MySQLCommandParameter
66
public int $Index;
77
public $Value;
88
public string $Type;
9-
public $Length;
9+
public ?int $Length;
1010

1111
public function __construct(int $paramIndex, $value, string $type, $length = NULL)
1212
{

berry/mysql/MySQLCommandParameters.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct()
1515
* @param type $parameter
1616
* @param type $type
1717
*/
18-
private function Add(int $paramIndex, $value, $type, $length = NULL)
18+
private function Add(int $paramIndex, $value, string $type, $length = NULL): void
1919
{
2020
$parameter = new MySQLCommandParameter($paramIndex, $value, $type, $length);
2121
$this->fParameters[$paramIndex] = $parameter;
@@ -27,7 +27,7 @@ private function Add(int $paramIndex, $value, $type, $length = NULL)
2727
* @param type $value
2828
* @param type $length
2929
*/
30-
public function setString(int $paramIndex, string $value, $length = NULL)
30+
public function setString(int $paramIndex, string $value, $length = NULL): void
3131
{
3232
$this->Add($paramIndex, $value, "s", $length);
3333
}
@@ -38,7 +38,7 @@ public function setString(int $paramIndex, string $value, $length = NULL)
3838
* @param type $value
3939
* @param type $length
4040
*/
41-
public function setInteger(int $paramIndex, int $value, $length = NULL)
41+
public function setInteger(int $paramIndex, int $value, $length = NULL): void
4242
{
4343
$this->Add($paramIndex, $value, "i", $length);
4444
}
@@ -49,7 +49,7 @@ public function setInteger(int $paramIndex, int $value, $length = NULL)
4949
* @param type $value
5050
* @param type $length
5151
*/
52-
public function setDouble(int $paramIndex, float $value, $length = NULL)
52+
public function setDouble(int $paramIndex, float $value, $length = NULL): void
5353
{
5454
$this->Add($paramIndex, $value, "d", $length);
5555
}
@@ -60,24 +60,24 @@ public function setDouble(int $paramIndex, float $value, $length = NULL)
6060
* @param type $value
6161
* @param type $length
6262
*/
63-
public function setBlob(int $paramIndex, $value, $length = NULL)
63+
public function setBlob(int $paramIndex, $value, $length = NULL): void
6464
{
6565
$this->Add($paramIndex, $value, "b", $length);
6666
}
6767

6868
/**
6969
* Remove all parameters
7070
*/
71-
public function Clear()
71+
public function Clear(): void
7272
{
7373
$this->fParameters = array();
7474
}
7575

76-
public function getParameters()
76+
public function getParameters(): array
7777
{
7878
return $this->fParameters;
7979
}
8080

8181
}
8282

83-
?>
83+
?>

berry/mysql/MySQLConnection.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class MySQLConnection
44
{
55

6-
private $fLink; // The mysqli link with the selected MySQL database
6+
private mysqli $fLink; // The mysqli link with the selected MySQL database
77

88
/**
99
* Constructs a new MySQLConnection
@@ -34,16 +34,15 @@ public function __construct(string $serverIP, string $database, string $user, st
3434
* @param string $string is the string to escape
3535
* @return the escaped string
3636
*/
37-
public function EscapeString(string $string)
37+
public function EscapeString(string $string): string
3838
{
39-
//return mysql_real_escape_string($string, $this->fLink);
4039
return mysqli_real_escape_string($this->fLink, $string);
4140
}
4241

4342
/**
4443
* Closes this MySQLConnection
4544
*/
46-
public function Close()
45+
public function Close(): void
4746
{
4847
$this->fLink->close();
4948
}
@@ -52,11 +51,11 @@ public function Close()
5251
* Returns the mysqli link with selected MySQL database.
5352
* @return mysqli
5453
*/
55-
public function getLink()
54+
public function getLink(): mysqli
5655
{
5756
return $this->fLink;
5857
}
5958

6059
}
6160

62-
?>
61+
?>

berry/mysql/MySQLDataReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ public function getValue($index)
8686

8787
}
8888

89-
?>
89+
?>

berry/utils/CrawlerDetector.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
<?php
22

3-
/*
4-
MIT License
5-
6-
Copyright (c) 2022 Nikos Siatras
7-
8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all
16-
copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24-
SOFTWARE.
25-
*/
26-
273
class CrawlerDetector
284
{
295

@@ -38,17 +14,13 @@ public function __construct()
3814
*
3915
* @return string returns the crawlers name or (String empty) ""
4016
*/
41-
public function getCrawlerName()
17+
public function getCrawlerName(): string
4218
{
4319
$USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
44-
45-
if (preg_match('/bot|wget|crawl|slurp|spider|mediapartners|facebook/i', $USER_AGENT))
46-
{
47-
return $USER_AGENT;
48-
}
49-
50-
return "";
20+
$pattern = '/bot|wget|crawl|slurp|spider|mediapartners|facebook/i';
21+
return preg_match($pattern, $USER_AGENT) ? $USER_AGENT : "";
5122
}
5223

5324
}
25+
5426
?>

berry/version.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
<?php
2-
// Version 1.0.2
2+
/*
3+
MIT License
4+
5+
Copyright (c) 2022 Nikolaos Siatras
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
25+
26+
// Version 1.0.3
327
?>
428

debug.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
require_once(__DIR__ . "/berry/utils.php"); // Include berry utils package
33

4-
// Initialize an HTMLHelper
5-
$htmlHelper = new HTMLHelper();
4+
$crawlerDetector = new CrawlerDetector();
5+
$crawlerName = $crawlerDetector->getCrawlerName();
66

7-
$string = "PHP-Berry framework for PHP backend applications";
8-
9-
// Convert $string to url friendly and print it
10-
print $htmlHelper->URLFriendly($string);
7+
if ($crawlerName != "")
8+
{
9+
print "Crawler Detected: " . $crawlerName;
10+
}
1111
?>

0 commit comments

Comments
 (0)