Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit fd3182b

Browse files
Merge pull request #2 from Mastercard/feature/fixing-code-smells
Fixing code smells
2 parents 5075ca4 + 32dda5b commit fd3182b

File tree

8 files changed

+14
-22
lines changed

8 files changed

+14
-22
lines changed

src/Developer/Encryption/FieldLevelEncryption.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
*/
1313
class FieldLevelEncryption {
1414

15-
private function __construct() {}
16-
1715
/**
1816
* Encrypt parts of a JSON payload using the given parameters and configuration.
1917
* @param $payload A JSON string
@@ -196,7 +194,7 @@ private static function addDecryptedDataToPayload($payloadJsonObject, $jsonPathO
196194
$outJsonObject->$key = $value;
197195
}
198196
}
199-
197+
200198
private static function readJsonElement($payloadJsonObject, $jsonPath) {
201199
return JsonPath::find($payloadJsonObject, $jsonPath);
202200
}
@@ -278,4 +276,4 @@ private static function sanitizeJson($json) {
278276
$json = str_replace("\t", '', $json);
279277
return str_replace("\r\n", '', $json);
280278
}
281-
}
279+
}

src/Developer/Encryption/FieldLevelEncryptionConfigBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class FieldLevelEncryptionConfigBuilder {
3333
private $encryptionKeyFingerprintHeaderName;
3434
private $fieldValueEncoding;
3535

36-
private function __construct() {}
37-
3836
/**
3937
* Get an instance of the builder.
4038
*/
@@ -318,4 +316,4 @@ private function computeEncryptionKeyFingerprintWhenNeeded() {
318316
throw new EncryptionException('Failed to compute encryption key fingerprint!', $e);
319317
}
320318
}
321-
}
319+
}

src/Developer/Interceptors/PsrStreamInterfaceImpl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function seek($offset, $whence = SEEK_SET) {
4040
return null;
4141
}
4242

43-
public function rewind() {}
43+
public function rewind() {
44+
return null;
45+
}
4446

4547
public function isWritable() {
4648
return false;
@@ -65,4 +67,4 @@ public function getContents() {
6567
public function getMetadata($key = null) {
6668
return [];
6769
}
68-
}
70+
}

src/Developer/Json/JsonPath.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class JsonPath {
1616
const FIRST_CHILD_KEY = "/(?:\[')([^\[\]]*)(?:'\])/"; // Returns "obj1" for "$['obj1']['obj2']"
1717
const FIRST_TOKEN_IN_PATH = "/(\['[^\[\]]*'\])/"; // Returns "['obj1']" for "$['obj1']['obj2']"
1818

19-
private function __construct() {}
20-
2119
/**
2220
* Convert the given JSON path to the following form: $['path']['to']['object'].
2321
* @throws \InvalidArgumentException
@@ -55,7 +53,7 @@ static function find($jsonObject, $path) {
5553
$currentElement = $jsonObject;
5654
while ($currentPath !== '$') {
5755
preg_match(self::FIRST_CHILD_KEY, $currentPath, $matches);
58-
if (sizeof($matches) <= 0) {
56+
if (sizeof($matches).isEmpty()) {
5957
return null;
6058
}
6159
$childKey = $matches[1];
@@ -121,7 +119,7 @@ static function getElementKey($path) {
121119

122120
throw new \InvalidArgumentException('Unsupported JSON path: ' . $path . '!');
123121
}
124-
122+
125123
/**
126124
* Checks if a JSON path points to a single item or if it potentially returns multiple items.
127125
* @link https://github.com/json-path/JsonPath
@@ -130,4 +128,4 @@ static function isPathDefinite($path) {
130128
return strpos($path, '*') === false && strpos($path, '..') === false
131129
&& strpos($path, '@') === false && strpos($path, ',') === false;
132130
}
133-
}
131+
}

src/Developer/Utils/EncodingUtils.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class EncodingUtils {
77

8-
private function __construct() {}
9-
108
static function encodeBytes($bytes, $encoding) {
119
return $encoding === FieldValueEncoding::HEX ? self::hexEncode($bytes) : base64_encode($bytes);
1210
}
@@ -47,4 +45,4 @@ static function pemToDer($pem, $header, $footer) {
4745
$der = str_replace($footer, '', $der);
4846
return base64_decode($der);
4947
}
50-
}
48+
}

src/Developer/Utils/EncryptionUtils.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class EncryptionUtils {
1414
const PKCS_8_PEM_HEADER = '-----BEGIN PRIVATE KEY-----';
1515
const PKCS_8_PEM_FOOTER = '-----END PRIVATE KEY-----';
1616

17-
private function __construct() {}
18-
1917
/**
2018
* Create an X.509 resource from the certificate data at the given file path.
2119
* @throws \InvalidArgumentException

tests/Developer/Encryption/FieldLevelEncryptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,4 +1267,4 @@ public function testDecryptPayload_ShouldThrowInvalidArgumentException_WhenEncry
12671267
// WHEN
12681268
FieldLevelEncryption::decryptPayload($encryptedPayload, $config, null);
12691269
}
1270-
}
1270+
}

tests/Developer/Interceptors/PsrStreamInterfaceImplTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testSeek() {
4646
}
4747

4848
public function testRewind() {
49-
$this->instanceUnderTest->rewind();
49+
$this->assertNull($this->instanceUnderTest->rewind());
5050
}
5151

5252
public function testIsWritable() {
@@ -74,4 +74,4 @@ public function testGetContents() {
7474
public function testGetMetadata() {
7575
$this->assertEquals([], $this->instanceUnderTest->getMetadata());
7676
}
77-
}
77+
}

0 commit comments

Comments
 (0)