Skip to content

Commit dc6a5c6

Browse files
Add files via upload
1 parent d769051 commit dc6a5c6

11 files changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class BlockChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid block type file." : "This is an invalid block type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class CharChecker {
4+
5+
public function check($file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid char type file." : "This is an invalid char type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
class CheckedFile {
4+
5+
public function __construct(
6+
public string $file,
7+
public string $violations,
8+
){}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class DirChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid dir type file." : "This is an invalid dir type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class FifoChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid Fifo type file." : "This is an invalid Fifo type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class FileChecker {
4+
5+
public function check($file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid file type file." : "This is an invalid file type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class LinkChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid link type file." : "This is an invalid link type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
require 'BlockChecker.php';
3+
require 'CharChecker.php';
4+
require 'DirChecker.php';
5+
require 'FifoChecker.php';
6+
require 'FileChecker.php';
7+
require 'LinkChecker.php';
8+
require 'NullChecker.php';
9+
require 'Socketchecker.php';
10+
require 'UnknownChecker.php';
11+
require 'CheckedFile.php';
12+
13+
class Nitpicker {
14+
15+
public function checkFile(string $file):object
16+
{
17+
18+
$violations = $this->getCheckerFor(file:$file)->check(file:$file);
19+
$checkedFile = new CheckedFile(file:$file,violations:$violations);
20+
21+
return $checkedFile;
22+
}
23+
24+
public function getCheckerFor(string $file):object
25+
{
26+
$checker = match(filetype($file)) {
27+
28+
'fifo' => new FifoChecker($file),
29+
'char' => new CharChecker($file),
30+
'dir' => new DirChecker($file),
31+
'block' => new BlockChecker($file),
32+
'link' => new LinkChecker($file),
33+
'file' => new FileChecker($file),
34+
'socket' => new SocketChecker($file),
35+
'unknown' => new UnknownChecker($file),
36+
default => new NullChecker($file),
37+
};
38+
return $checker;
39+
}
40+
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
class NullChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = "The filetype of this file is unknown.";
8+
9+
return $violations;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class SocketChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid socket type file." : "This is an invalid socket type file.";
8+
return $violations;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class UnknownChecker {
4+
5+
public function check(string $file):string
6+
{
7+
$violations = is_file($file) ? "This is a valid unknown type file." : "This is an invalid unknown type file.";
8+
return $violations;
9+
}
10+
}

0 commit comments

Comments
 (0)