Updated LICENSE

Fixed namespace usages for polyfill packages
Added dependency Symfony\polyfill-uuid
Updated .gitignore
Updated autoload.php
Corrected .gitignore
Added dependency nikic\PhpParser
Removed .idea leftovers
Added classes & objects for Package Structure 1.0
Updated autoload.php for tests
This commit is contained in:
Netkas 2022-09-26 17:45:04 -04:00
parent 9bab67f734
commit 36d89bae8a
322 changed files with 119031 additions and 103 deletions

View file

@ -1,8 +1,12 @@
<?php
$SourceDirectory = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'ncc';
$BuildDirectory = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'build';
$AutoloadPath = $BuildDirectory . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'autoload.php';
if(file_exists($SourceDirectory . DIRECTORY_SEPARATOR . 'autoload.php') == false)
throw new RuntimeException('The autoload file was not found in \'' . $SourceDirectory . '\'');
if(!file_exists($BuildDirectory) || !is_dir($BuildDirectory))
throw new RuntimeException('Build directory does not exist, to run tests you must build the project.');
require($SourceDirectory . DIRECTORY_SEPARATOR . 'autoload.php');
if(!file($AutoloadPath) || !is_file($AutoloadPath))
throw new RuntimeException('Autoload file does not exist in \'' . $BuildDirectory .'\', to run tests you must build the project.');
require($AutoloadPath);

View file

@ -0,0 +1,8 @@
# Example Project
This is a simple library that provides very basic functionality,
this project is a means to test the compiler capabilities of NCC
### Generating a project configuration file.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,65 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace ExampleLibrary;
use ExampleLibrary\Exceptions\FileNotFoundException;
use ExampleLibrary\Objects\Person;
class ExampleLibrary
{
/**
* @var string[]
*/
private $FirstNames;
/**
* @var string[]
*/
private $LastNames;
/**
* Public Constructor
*
* @throws FileNotFoundException
*/
public function __construct()
{
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'first_names.txt'))
throw new FileNotFoundException('The file first_names.txt does not exist in the data directory.');
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'last_names.txt'))
throw new FileNotFoundException('The file last_names.txt does not exist in the data directory.');
$first_names = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'first_names.txt');
$this->FirstNames = explode("\n", $first_names);
$last_names = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'last_names.txt');
$this->LastNames = explode("\n", $last_names);
}
/**
* Returns an array of randomly generated
*
* @param int $amount
* @return array
* @throws Exceptions\InvalidNameException
*/
public function generatePeople(int $amount=10): array
{
$results = [];
for ($k = 0 ; $k < $amount; $k++)
{
$FullName = implode(' ', [
$this->FirstNames[array_rand($this->FirstNames)],
$this->LastNames[array_rand($this->LastNames)]
]);
$results[] = new Person($FullName);
}
return $results;
}
}

View file

@ -0,0 +1,29 @@
<?php
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ExampleLibrary\Exceptions;
use Exception;
use Throwable;
class FileNotFoundException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->message = $message;
$this->code = $code;
$this->previous = $previous;
}
}

View file

@ -0,0 +1,26 @@
<?php
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ExampleLibrary\Exceptions;
use Exception;
use Throwable;
class InvalidNameException extends Exception
{
private ?Throwable $previous;
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->message = $message;
$this->code = $code;
$this->previous = $previous;
}
}

View file

@ -0,0 +1,123 @@
<?php
namespace ExampleLibrary\Objects;
use ExampleLibrary\Exceptions\InvalidNameException;
class Person
{
/**
* @var string
*/
private string $FirstName;
/**
* @var string
*/
private string $LastName;
/**
* Public Constructor
*
* @param string|null $name
* @throws InvalidNameException
*/
public function __construct(?string $name=null)
{
if($name !== null)
{
$exploded_name = explode(' ', $name);
if(count($exploded_name) < 2)
{
throw new InvalidNameException('The given name must contain a first and last name.');
}
$this->FirstName = $exploded_name[0];
$this->LastName = $exploded_name[1];
}
}
/**
* Sets the first name of the person.
*
* @param string $FirstName
*/
public function setFirstName(string $FirstName): void
{
$this->FirstName = $FirstName;
}
/**
* Gets the last name of the person.
*
* @return string
*/
public function getLastName(): string
{
return $this->LastName;
}
/**
* Sets the last name of the person.
*
* @param string $LastName
*/
public function setLastName(string $LastName): void
{
$this->LastName = $LastName;
}
/**
* Gets the first name of the person.
*
* @return string
*/
public function getFirstName(): string
{
return $this->FirstName;
}
/**
* Returns a string representation of the person.
*
* @return string
*/
public function __toString()
{
return implode(' ', [$this->FirstName, $this->LastName]);
}
/**
* Returns an array representation of the person
*
* @return array
*/
public function toArray(): array
{
return [
'first_name' => $this->FirstName,
'last_name' => $this->LastName
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return Person
*/
public static function fromArray(array $data): Person
{
$person = new Person();
if(isset($data['first_name']))
$person->FirstName = $data['first_name'];
if(isset($data['last_name']))
$person->LastName = $data['last_name'];
return $person;
}
}

View file

@ -0,0 +1,13 @@
<?php
require(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php');
$Scanner = new \ncc\ThirdParty\theseer\DirectoryScanner\DirectoryScanner();
$Basedir = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
/** @var SplFileInfo $item */
foreach($Scanner($Basedir . DIRECTORY_SEPARATOR . 'src', true) as $item)
{
var_dump($item->getPath());
var_dump($item);
}