-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d769051
commit dc6a5c6
Showing
11 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class BlockChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid block type file." : "This is an invalid block type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class CharChecker { | ||
|
||
public function check($file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid char type file." : "This is an invalid char type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
class CheckedFile { | ||
|
||
public function __construct( | ||
public string $file, | ||
public string $violations, | ||
){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class DirChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid dir type file." : "This is an invalid dir type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class FifoChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid Fifo type file." : "This is an invalid Fifo type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class FileChecker { | ||
|
||
public function check($file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid file type file." : "This is an invalid file type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class LinkChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid link type file." : "This is an invalid link type file."; | ||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
require 'BlockChecker.php'; | ||
require 'CharChecker.php'; | ||
require 'DirChecker.php'; | ||
require 'FifoChecker.php'; | ||
require 'FileChecker.php'; | ||
require 'LinkChecker.php'; | ||
require 'NullChecker.php'; | ||
require 'Socketchecker.php'; | ||
require 'UnknownChecker.php'; | ||
require 'CheckedFile.php'; | ||
|
||
class Nitpicker { | ||
|
||
public function checkFile(string $file):object | ||
{ | ||
|
||
$violations = $this->getCheckerFor(file:$file)->check(file:$file); | ||
$checkedFile = new CheckedFile(file:$file,violations:$violations); | ||
|
||
return $checkedFile; | ||
} | ||
|
||
public function getCheckerFor(string $file):object | ||
{ | ||
$checker = match(filetype($file)) { | ||
|
||
'fifo' => new FifoChecker($file), | ||
'char' => new CharChecker($file), | ||
'dir' => new DirChecker($file), | ||
'block' => new BlockChecker($file), | ||
'link' => new LinkChecker($file), | ||
'file' => new FileChecker($file), | ||
'socket' => new SocketChecker($file), | ||
'unknown' => new UnknownChecker($file), | ||
default => new NullChecker($file), | ||
}; | ||
return $checker; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class NullChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = "The filetype of this file is unknown."; | ||
|
||
return $violations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class SocketChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid socket type file." : "This is an invalid socket type file."; | ||
return $violations; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
7. Choosing a Syntax Handler/imperative/UnknownChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class UnknownChecker { | ||
|
||
public function check(string $file):string | ||
{ | ||
$violations = is_file($file) ? "This is a valid unknown type file." : "This is an invalid unknown type file."; | ||
return $violations; | ||
} | ||
} |