Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 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
8 changes: 4 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>src/vfsStreamWrapper.php</exclude-pattern>
<exclude-pattern>src/StreamWrapper.php</exclude-pattern>
</rule>

<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
Expand All @@ -35,15 +35,15 @@
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
<exclude-pattern>tests/phpunit/vfsStreamDirectoryIssue134TestCase.php</exclude-pattern>
<exclude-pattern>tests/phpunit/Issue134TestCase.php</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php</exclude-pattern>
<exclude-pattern>tests/phpunit/StreamWrapperAlreadyRegisteredTestCase.php</exclude-pattern>
</rule>

<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php</exclude-pattern>
<exclude-pattern>tests/phpunit/StreamWrapperAlreadyRegisteredTestCase.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ parameters:
ignoreErrors:
-
message: '/Default value of the parameter #1 \$out \(mixed\) of method [a-zA-Z0-9\\_]+::__construct\(\) is incompatible with type resource/'
path: %currentWorkingDirectory%/src/visitor/vfsStreamPrintVisitor.php
path: %currentWorkingDirectory%/src/visitor/Printer.php
188 changes: 188 additions & 0 deletions src/BasicFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

declare(strict_types=1);

/**
* This file is part of vfsStream.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package bovigo\vfs
*/

namespace bovigo\vfs;

use function array_merge;
use function array_values;
use function spl_object_id;
use function strstr;

/**
* Represents a basic entry in the file system.
*
* Due to simplicity reasons it extends Inode, even though that is not a correct
* implementation if when looked from a domain point of view.
*
* @internal
*/
abstract class BasicFile extends Inode
{
/** @var string */
private $name;
/**
* path to to this file
*
* @var string|null
*/
private $parentPath;

public function __construct(string $name, int $permissions)
{
$this->check($name);
$this->name = $name;
parent::__construct($permissions);
}

private function check(string $name): void
{
if (strstr($name, '/') !== false) {
throw new vfsStreamException('Name can not contain /.');
}
}

/**
* renames the file
*/
public function rename(string $newName): void
{
$this->check($newName);
$this->name = $newName;
}

/**
* @deprecated use name() instead
*/
public function getName(): string
{
return $this->name();
}

/**
* @api
*/
public function name(): string
{
return $this->name;
}

/**
* checks whether the file can be applied to given name
*/
public function appliesTo(string $name): bool
{
return $this->name === $name;
}

/**
* @deprecated use type() instead
*/
public function getType(): int
{
return $this->type();
}

/**
* returns the type of the file
*/
abstract public function type(): int;

/**
* returns size of content
*/
abstract public function size(): int;

/**
* sets parent path
*
* @internal only to be set by parent
*
* @since 1.2.0
*/
public function setParentPath(string $parentPath): void
{
$this->parentPath = $parentPath;
}

/**
* removes parent path
*
* @internal only to be set by parent
*
* @since 2.0.0
*/
public function removeParentPath(): void
{
$this->parentPath = null;
}

/**
* returns path to this content
*
* @api
* @since 1.2.0
*/
public function path(): string
{
if ($this->parentPath === null) {
return $this->name;
}

return $this->parentPath . '/' . $this->name;
}

/**
* returns complete vfsStream url for this content
*
* @api
* @since 1.2.0
*/
public function url(): string
{
return vfsStream::url($this->path());
}

/**
* returns status of file
*
* @return int[]|false
*/
public function stat()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting that here eliminates some code duplication in the streamwrapper class.

{
$atime = $this->fileatime();
$ctime = $this->filectime();
$mtime = $this->filemtime();
$size = $this->size();
if ($atime === -1 || $ctime === -1 || $mtime === -1 || $size === -1) {
return false;
}

$fileStat = [
'dev' => 0,
'ino' => spl_object_id($this),
'mode' => $this->type() | $this->permissions(),
'nlink' => 0,
'uid' => $this->user(),
'gid' => $this->group(),
'rdev' => 0,
'size' => $size,
'atime' => $atime,
'mtime' => $mtime,
'ctime' => $ctime,
'blksize' => -1,
'blocks' => -1,
];

return array_merge(array_values($fileStat), $fileStat);
}
}
2 changes: 1 addition & 1 deletion src/DotDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Directory container.
*/
class DotDirectory extends vfsStreamDirectory
class DotDirectory extends vfsDirectory
{
/**
* returns iterator for the children
Expand Down
Loading