Skip to content

Commit b4f936d

Browse files
committed
Improve the code style and add a Makefile to run tests
1 parent fd66ab1 commit b4f936d

File tree

7 files changed

+32
-35
lines changed

7 files changed

+32
-35
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.PHONY: install tests
2+
3+
all: install
4+
5+
install:
6+
composer install
7+
8+
tests:
9+
bin/phpunit

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
"symfony/framework-bundle": "^4.4|^5.1",
2626
"doctrine/doctrine-bundle": "*",
2727
"doctrine/orm": "*",
28-
"symfony/stopwatch": "^4.4|^5.1",
2928
"symfony/security":"^4.4|^5.1"
3029
},
3130
"require-dev": {
31+
"symfony/stopwatch": "^4.4|^5.1",
3232
"phpunit/phpunit": "^9.4"
3333
},
3434
"suggest": {
35-
"doctrine/doctrine-bundle": "Use Doctrine to encrypt and decrypt entities automatically",
3635
"ext-sodium": "The Sodium library is native in PHP 7.2",
3736
"ext-mcrypt": "Don't use this except for backward compatibility purpose",
3837
"paragonie/sodium_compat": "Use this for a Sodium polyfill",

src/Doctrine/Connection/Factory/ConnectionFactory.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Doctrine\Common\EventManager;
66
use Doctrine\DBAL\Configuration;
77
use Doctrine\DBAL\Connection;
8-
use Doctrine\DBAL\DBALException;
98
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
109
use Doctrine\DBAL\DriverManager;
1110
use Doctrine\DBAL\Exception\DriverException;
@@ -48,7 +47,7 @@ public function createConnection(array $params, Configuration $config = null, Ev
4847
$wrapperClass = null;
4948
if (isset($params['wrapperClass'])) {
5049
if (! is_subclass_of($params['wrapperClass'], Connection::class)) {
51-
throw DBALException::invalidWrapperClass($params['wrapperClass']);
50+
throw \Doctrine\DBAL\Exception::invalidWrapperClass($params['wrapperClass']);
5251
}
5352

5453
$wrapperClass = $params['wrapperClass'];
@@ -97,14 +96,14 @@ public function createConnection(array $params, Configuration $config = null, Ev
9796
* and the platform version is unknown.
9897
* For details have a look at DoctrineBundle issue #673.
9998
*
100-
* @throws DBALException
99+
* @throws \Doctrine\DBAL\Exception
101100
*/
102101
private function getDatabasePlatform(Connection $connection) : AbstractPlatform
103102
{
104103
try {
105104
return $connection->getDatabasePlatform();
106105
} catch (DriverException $driverException) {
107-
throw new DBALException(
106+
throw new \Doctrine\DBAL\Exception(
108107
'An exception occurred while establishing a connection to figure out your platform version.' . PHP_EOL .
109108
"You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
110109
'For further information have a look at:' . PHP_EOL .

src/Encryption/AbstractEncryptionAdapter.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ abstract class AbstractEncryptionAdapter implements EncryptionAdapterInterface
2222
{
2323
protected const ENCODING = '8bit';
2424

25-
/** @var int */
26-
protected $nonceSize;
27-
28-
/** @var int */
29-
protected $keySize;
30-
31-
/** @var int */
32-
protected $clearTextBlockSize;
33-
34-
/** @var int */
35-
protected $encryptedBlockSize;
25+
protected int $nonceSize;
26+
protected int $keySize;
27+
protected int $clearTextBlockSize;
28+
protected int $encryptedBlockSize;
3629

3730
/**
3831
* {@inheritdoc}

src/Entity/CryptableInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public function getEncryptedProperties(): array;
3939
* @return bool
4040
*/
4141
public function getIsEncrypted(): bool;
42-
42+
4343
/**
4444
* Set the encryption state of the entity
4545
*
4646
* @param bool $bool
4747
*/
48-
public function setIsEncrypted($bool): void;
48+
public function setIsEncrypted(bool $bool): void;
4949

5050
/**
5151
* Identifies a cipher key to encrypt/decrypt only related entities

src/HttpFoundation/DecryptFileResponse.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@
2424
*/
2525
class DecryptFileResponse extends BinaryFileResponse
2626
{
27-
/** @var int */
28-
protected $fileSize;
29-
30-
/** @var EncryptionManagerInterface */
31-
protected $encryptionManager;
32-
33-
/** @var UserEncryptionProviderInterface */
34-
protected $user;
35-
27+
protected int $fileSize;
28+
protected EncryptionManagerInterface $encryptionManager;
29+
protected UserEncryptionProviderInterface $user;
30+
3631
/**
3732
* Initialize the response with the file path and the original's file size
3833
* The original file's size is very important to prevent the null character padding of the encryption function at
@@ -51,12 +46,12 @@ class DecryptFileResponse extends BinaryFileResponse
5146
public function __construct(
5247
EncryptionManagerInterface $encryptionManager,
5348
$file,
54-
$fileSize,
55-
$status = 200,
56-
$headers = [],
57-
$contentDisposition = null,
58-
$autoEtag = false,
59-
$autoLastModified = true
49+
int $fileSize,
50+
int $status = 200,
51+
array $headers = [],
52+
?string $contentDisposition = null,
53+
bool $autoEtag = false,
54+
bool $autoLastModified = true
6055
) {
6156
parent::__construct($file, $status, $headers, false, $contentDisposition, $autoEtag, $autoLastModified);
6257
$this->setPrivate();

src/Resources/config/services/registry.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ services:
22
Sidus\EncryptionBundle\Registry\EncryptionManagerRegistry:
33
public: false
44
arguments:
5-
$defaultManager: ~
5+
# The default encryption manager code will be replaced in
6+
# \Sidus\EncryptionBundle\DependencyInjection\SidusEncryptionExtension
7+
$defaultCode: ~
68
$managers: !tagged {tag: sidus.encryption.manager, default_index_method: getCode}

0 commit comments

Comments
 (0)