66use amculin \cryptography \classic \exceptions \InvalidAlnumException ;
77
88/**
9- * This file is the main class for alpha-numric mode vigenere cipher algortithm
9+ * This file is the main class for alpha-numric mode vigenere cipher algortithm.
1010 *
1111 * @author Fahmi Auliya Tsani <[email protected] > 12+ *
1213 * @version 1.1
14+ *
1315 * @psalm-api
1416 */
1517class AlnumVigenereCipher extends VigenereCipherBlueprint
@@ -39,60 +41,48 @@ public function __construct(
3941 }
4042 }
4143
42- /**
43- * @inheritdoc
44- */
4544 public function isValidKey (string $ pattern ): bool
4645 {
47- if ($ pattern != '' ) {
48- return preg_match ($ pattern , $ this ->key ) == 1 ;
46+ if ('' != $ pattern ) {
47+ return 1 == preg_match ($ pattern , $ this ->key );
4948 }
5049
5150 return false ;
5251 }
5352
54- /**
55- * @inheritdoc
56- */
5753 public function isValidPlainText (string $ pattern ): bool
5854 {
59- if ($ pattern != '' ) {
60- return preg_match ($ pattern , $ this ->plainText ) == 1 ;
55+ if ('' != $ pattern ) {
56+ return 1 == preg_match ($ pattern , $ this ->plainText );
6157 }
6258
6359 return false ;
6460 }
6561
66- /**
67- * @inheritdoc
68- */
6962 public function isValidCipherText (string $ pattern ): bool
7063 {
71- if ($ pattern != '' ) {
72- return preg_match ($ pattern , $ this ->cipherText ) == 1 ;
64+ if ('' != $ pattern ) {
65+ return 1 == preg_match ($ pattern , $ this ->cipherText );
7366 }
7467
7568 return false ;
7669 }
7770
78- /**
79- * @inheritdoc
80- */
8171 public function isValid (): bool
8272 {
8373 try {
8474 $ pattern = '/^[a-zA-Z0-9]*$/ ' ;
8575
86- if (! $ this ->isValidKey ($ pattern )) {
76+ if (!$ this ->isValidKey ($ pattern )) {
8777 throw new InvalidAlnumException ('Key ' );
8878 }
8979
9080 if ($ this ->process == ProcessType::ENCRYPT ->value ) {
91- if (! $ this ->isValidPlainText ($ pattern )) {
81+ if (!$ this ->isValidPlainText ($ pattern )) {
9282 throw new InvalidAlnumException ('Plain text ' );
9383 }
9484 } else {
95- if (! $ this ->isValidCipherText ($ pattern )) {
85+ if (!$ this ->isValidCipherText ($ pattern )) {
9686 throw new InvalidAlnumException ('Cipher text ' );
9787 }
9888 }
@@ -103,6 +93,7 @@ public function isValid(): bool
10393 }
10494
10595 $ this ->setIsValid (true );
96+
10697 return true ;
10798 }
10899}
0 commit comments