Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-WEB-DEVELOPMENT authored Jul 20, 2023
1 parent d769051 commit dc6a5c6
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/BlockChecker.php
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;
}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/CharChecker.php
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;
}
}
9 changes: 9 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/CheckedFile.php
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,
){}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/DirChecker.php
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;
}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/FifoChecker.php
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;
}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/FileChecker.php
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;
}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/LinkChecker.php
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;
}
}
41 changes: 41 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/Nitpicker.php
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;
}

}
11 changes: 11 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/NullChecker.php
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;
}
}
10 changes: 10 additions & 0 deletions 7. Choosing a Syntax Handler/imperative/SocketChecker.php
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 7. Choosing a Syntax Handler/imperative/UnknownChecker.php
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;
}
}

0 comments on commit dc6a5c6

Please sign in to comment.