for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace FileFetcher;
use InvalidArgumentException;
/**
* @since 3.1
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class InMemoryFileFetcher implements FileFetcher {
* @param string[] $files
* @throws InvalidArgumentException
public function __construct( array $files ) {
foreach ( $files as $url => $fileContents ) {
if ( !is_string( $url ) || !is_string( $fileContents ) ) {
throw new InvalidArgumentException( 'Both file url and file contents need to be of type string' );
}
$this->files = $files;
files
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
* @see FileFetcher::fetchFile
* @param string $fileUrl
* @return string
* @throws FileFetchingException
public function fetchFile( $fileUrl ) {
if ( array_key_exists( $fileUrl, $this->files ) ) {
return $this->files[$fileUrl];
throw new FileFetchingException( $fileUrl );
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: