Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

chore(php) Move to PHP 7 #29

Merged
merged 6 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 18 additions & 56 deletions Directory.php → Source/Directory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -42,51 +44,36 @@
* Class \Hoa\File\Directory.
*
* Directory handler.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Directory extends Generic
{
/**
* Open for reading.
*
* @const string
*/
const MODE_READ = 'rb';
public const MODE_READ = 'rb';

/**
* Open for reading and writing. If the directory does not exist, attempt to
* create it.
*
* @const string
*/
const MODE_CREATE = 'xb';
public const MODE_CREATE = 'xb';

/**
* Open for reading and writing. If the directory does not exist, attempt to
* create it recursively.
*
* @const string
*/
const MODE_CREATE_RECURSIVE = 'xrb';
public const MODE_CREATE_RECURSIVE = 'xrb';



/**
* Open a directory.
*
* @param string $streamName Stream name.
* @param string $mode Open mode, see the self::MODE* constants.
* @param string $context Context ID (please, see the
* \Hoa\Stream\Context class).
* @param bool $wait Differ opening or not.
*/
public function __construct(
$streamName,
$mode = self::MODE_READ,
$context = null,
$wait = false
string $streamName,
string $mode = self::MODE_READ,
string $context = null,
bool $wait = false
) {
$this->setMode($mode);
parent::__construct($streamName, $context, $wait);
Expand All @@ -96,14 +83,8 @@ public function __construct(

/**
* Open the stream and return the associated resource.
*
* @param string $streamName Stream name (e.g. path or URL).
* @param \Hoa\Stream\Context $context Context.
* @return resource
* @throws \Hoa\File\Exception\FileDoesNotExist
* @throws \Hoa\File\Exception
*/
protected function &_open($streamName, Stream\Context $context = null)
protected function &_open(string $streamName, Stream\Context $context = null)
{
if (false === is_dir($streamName)) {
if ($this->getMode() == self::MODE_READ) {
Expand All @@ -130,25 +111,16 @@ protected function &_open($streamName, Stream\Context $context = null)

/**
* Close the current stream.
*
* @return bool
*/
protected function _close()
protected function _close(): bool
{
return true;
}

/**
* Recursive copy of a directory.
*
* @param string $to Destination path.
* @param bool $force Force to copy if the file $to already exists.
* Use the \Hoa\Stream\IStream\Touchable::*OVERWRITE
* constants.
* @return bool
* @throws \Hoa\File\Exception
*/
public function copy($to, $force = Stream\IStream\Touchable::DO_NOT_OVERWRITE)
public function copy(string $to, bool $force = Stream\IStream\Touchable::DO_NOT_OVERWRITE): bool
{
if (empty($to)) {
throw new Exception(
Expand Down Expand Up @@ -184,7 +156,7 @@ public function copy($to, $force = Stream\IStream\Touchable::DO_NOT_OVERWRITE)
if (true === $file->isFile()) {
$handle = new Read($file->getPathname());
} elseif (true === $file->isDir()) {
$handle = new Directory($file->getPathName());
$handle = new self($file->getPathName());
} elseif (true === $file->isLink()) {
$handle = new Link\Read($file->getPathName());
}
Expand All @@ -200,10 +172,8 @@ public function copy($to, $force = Stream\IStream\Touchable::DO_NOT_OVERWRITE)

/**
* Delete a directory.
*
* @return bool
*/
public function delete()
public function delete(): bool
{
$from = $this->getStreamName();
$finder = new Finder();
Expand All @@ -224,20 +194,12 @@ public function delete()

/**
* Create a directory.
*
* @param string $name Directory name.
* @param string $mode Create mode. Please, see the self::MODE_CREATE*
* constants.
* @param string $context Context ID (please, see the
* \Hoa\Stream\Context class).
* @return bool
* @throws \Hoa\File\Exception
*/
public static function create(
$name,
$mode = self::MODE_CREATE_RECURSIVE,
$context = null
) {
string $name,
string $mode = self::MODE_CREATE_RECURSIVE,
string $context = null
): bool {
if (true === is_dir($name)) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion Exception/Exception.php → Source/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -44,7 +46,6 @@
*
* Extending the \Hoa\Exception\Exception class.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends HoaException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -41,7 +43,6 @@
*
* Extending the \Hoa\File\Exception class.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class FileDoesNotExist extends Exception
Expand Down
Loading