Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @type to @var #186

Merged
merged 4 commits into from Apr 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@

* raised minimum required PHP version to 7.2.0
* all methods of `org\bovigo\vfs\visitor\vfsStreamVisitor` are now declared with `self` as return type
* `vfsStreamWrapper::setRoot()` and `vsfStreamWrapper::getRoot()` method signatures now require and return `org\bovigo\vfs\vfsStreamDirectory` vice `org\bovigo\vfs\vfsStreamContainer`.


1.6.6 (2019-04-08)
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/org/bovigo/vfs/Quota.php
Expand Up @@ -26,7 +26,7 @@ class Quota
*
* A value of -1 is treated as unlimited.
*
* @type int
* @var int
*/
private $amount;

Expand Down
18 changes: 18 additions & 0 deletions src/main/php/org/bovigo/vfs/content/FileContent.php
Expand Up @@ -69,4 +69,22 @@ public function write(string $data): int;
* @return bool
*/
public function truncate(int $size): bool;

/**
* Returns the current position within the file.
*
* @return int
* @api
*/
public function bytesRead(): int;

/**
* Returns the content until its end from current offset.
*
* Using this method changes the time when the file was last accessed.
*
* @return string
* @api
*/
public function readUntilEnd(): string;
}
4 changes: 2 additions & 2 deletions src/main/php/org/bovigo/vfs/content/LargeFileContent.php
Expand Up @@ -28,13 +28,13 @@ class LargeFileContent extends SeekableFileContent implements FileContent
/**
* byte array of written content
*
* @type char[]
* @var array
*/
private $content = [];
/**
* file size in bytes
*
* @type int
* @var int
*/
private $size;

Expand Down
6 changes: 3 additions & 3 deletions src/main/php/org/bovigo/vfs/content/SeekableFileContent.php
Expand Up @@ -19,7 +19,7 @@ abstract class SeekableFileContent implements FileContent
/**
* current position within content
*
* @type int
* @var int
*/
private $offset = 0;

Expand Down Expand Up @@ -117,7 +117,7 @@ protected abstract function doWrite(string $data, int $offset, int $length);
* for backwards compatibility with vfsStreamFile::bytesRead()
*
* @return int
* @deprecated
* @api
*/
public function bytesRead(): int
{
Expand All @@ -128,7 +128,7 @@ public function bytesRead(): int
* for backwards compatibility with vfsStreamFile::readUntilEnd()
*
* @return string
* @deprecated
* @api
*/
public function readUntilEnd(): string
{
Expand Down
Expand Up @@ -19,7 +19,7 @@ class StringBasedFileContent extends SeekableFileContent implements FileContent
/**
* actual content
*
* @type string
* @var string
*/
private $content;

Expand Down
4 changes: 2 additions & 2 deletions src/main/php/org/bovigo/vfs/vfsStream.php
Expand Up @@ -50,13 +50,13 @@ class vfsStream
/**
* initial umask setting
*
* @type int
* @var int
*/
protected static $umask = 0000;
/**
* switch whether dotfiles are enabled in directory listings
*
* @type bool
* @var bool
*/
private static $dotFiles = true;

Expand Down
22 changes: 11 additions & 11 deletions src/main/php/org/bovigo/vfs/vfsStreamAbstractContent.php
Expand Up @@ -17,63 +17,63 @@ abstract class vfsStreamAbstractContent implements vfsStreamContent
/**
* name of the container
*
* @type string
* @var string
*/
protected $name;
/**
* type of the container
*
* @type string
* @var int
*/
protected $type;
/**
* timestamp of last access
*
* @type int
* @var int
*/
protected $lastAccessed;
/**
* timestamp of last attribute modification
*
* @type int
* @var int
*/
protected $lastAttributeModified;
/**
* timestamp of last modification
*
* @type int
* @var int
*/
protected $lastModified;
/**
* permissions for content
*
* @type int
* @var int
*/
protected $permissions;
/**
* owner of the file
*
* @type int
* @var int
*/
protected $user;
/**
* owner group of the file
*
* @type int
* @var int
*/
protected $group;
/**
* path to to this content
*
* @type string
* @var string|null
*/
private $parentPath;

/**
* constructor
*
* @param string $name
* @param int $permissions optional
* @param string $name
* @param int|null $permissions optional
*/
public function __construct(string $name, int $permissions = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/org/bovigo/vfs/vfsStreamContainerIterator.php
Expand Up @@ -17,7 +17,7 @@ class vfsStreamContainerIterator implements \Iterator
/**
* list of children from container to iterate over
*
* @type vfsStreamContent[]
* @var vfsStreamContent[]
*/
protected $children;

Expand Down
10 changes: 7 additions & 3 deletions src/main/php/org/bovigo/vfs/vfsStreamDirectory.php
Expand Up @@ -19,7 +19,7 @@ class vfsStreamDirectory extends vfsStreamAbstractContent implements vfsStreamCo
/**
* list of directory children
*
* @type vfsStreamContent[]
* @var vfsStreamContent[]
*/
protected $children = [];

Expand Down Expand Up @@ -73,7 +73,7 @@ public function sizeSummarized(): int
{
$size = 0;
foreach ($this->children as $child) {
if ($child->getType() === vfsStreamContent::TYPE_DIR) {
if ($child instanceof self) {
$size += $child->sizeSummarized();
} else {
$size += $child->size();
Expand Down Expand Up @@ -181,7 +181,11 @@ public function getChild(string $name): ?vfsStreamContent
return $child;
}

if ($child->appliesTo($childName) === true && $child->hasChild($childName) === true) {
if (!$child instanceof vfsStreamContainer) {
continue;
}

if ($child->appliesTo($childName) && $child->hasChild($childName)) {
return $child->getChild($childName);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/php/org/bovigo/vfs/vfsStreamFile.php
Expand Up @@ -21,19 +21,19 @@ class vfsStreamFile extends vfsStreamAbstractContent
/**
* content of the file
*
* @type FileContent
* @var FileContent
*/
private $content;
/**
* Resource id which exclusively locked this file
*
* @type string
* @var string|null
*/
protected $exclusiveLock;
/**
* Resources ids which currently holds shared lock to this file
*
* @type bool[string]
* @var array<string, bool>

Choose a reason for hiding this comment

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

Is this valid PHPDoc? I have never seen this style used before with any PHP documentation parser/generator.

I would think bool[]|string[]. If you wanted more accuracy, (bool|string)[]. This form is from the PSR-5 draft and isn't widely supported yet though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually a bool[] indexed by string. The doc format is PHP Generics, which is still just an RFC but is what phpstan uses to add more detail to known data structures. It's essentially a <key, value> comment, in this case. Generics can be used for a lot more than that. There's big projects that have some usage of it, but not a lot.

Documenting it using the generics syntax will help static analysis tools ensure data quality, as it should trigger an error if someone ever tries to use a non-string as an index in that array.

Alternatively, it could be @var bool[] Indexed by string but it'll be a little less helpful for static analysis.

Choose a reason for hiding this comment

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

Ah I see! I knew about the Generics syntax, but didn't realize you could apply it to array.

Copy link
Contributor

Choose a reason for hiding this comment

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

And yes this is a valid phpdoc, we introduced that I think about 4 years ago ;-)

*/
protected $sharedLock = [];

Expand Down Expand Up @@ -176,7 +176,7 @@ public function read(int $count): string
* Using this method changes the time when the file was last accessed.
*
* @return string
* @deprecated since 1.3.0
* @api since 1.3.0
*/
public function readUntilEnd(): string
{
Expand Down Expand Up @@ -226,7 +226,7 @@ public function eof(): bool
* returns the current position within the file
*
* @return int
* @deprecated since 1.3.0
* @api since 1.3.0
*/
public function getBytesRead(): int
{
Expand Down Expand Up @@ -366,7 +366,8 @@ public function hasSharedLock($resource = null): bool
* @return string
* @see https://github.com/mikey179/vfsStream/issues/40
*/
public function getResourceId($resource): string {
public function getResourceId($resource): string
{
if (is_resource($resource)) {
$data = stream_get_meta_data($resource);
$resource = $data['wrapper_data'];
Expand Down
24 changes: 12 additions & 12 deletions src/main/php/org/bovigo/vfs/vfsStreamWrapper.php
Expand Up @@ -50,43 +50,43 @@ class vfsStreamWrapper
/**
* switch whether class has already been registered as stream wrapper or not
*
* @type bool
* @var bool
*/
protected static $registered = false;
/**
* root content
*
* @type vfsStreamContent
* @var vfsStreamDirectory|null
*/
protected static $root;
/**
* disk space quota
*
* @type Quota
* @var Quota
*/
private static $quota;
/**
* file mode: read only, write only, all
*
* @type int
* @var int
*/
protected $mode;
/**
* shortcut to file container
*
* @type vfsStreamFile
* @var vfsStreamFile|null
*/
protected $content;
/**
* shortcut to directory container
*
* @type vfsStreamDirectory
* @var vfsStreamDirectory|null
*/
protected $dir;
/**
* shortcut to directory container iterator
*
* @type vfsStreamDirectory
* @var vfsStreamContainerIterator|null
*/
protected $dirIterator;

Expand Down Expand Up @@ -146,10 +146,10 @@ public static function unregister()
/**
* sets the root content
*
* @param vfsStreamContainer $root
* @return vfsStreamContainer|null
* @param vfsStreamDirectory $root
* @return vfsStreamDirectory
*/
public static function setRoot(vfsStreamContainer $root): ?vfsStreamContainer
public static function setRoot(vfsStreamDirectory $root): vfsStreamDirectory
{
self::$root = $root;
clearstatcache();
Expand All @@ -159,9 +159,9 @@ public static function setRoot(vfsStreamContainer $root): ?vfsStreamContainer
/**
* returns the root content
*
* @return vfsStreamContainer|null
* @return vfsStreamDirectory|null
*/
public static function getRoot(): ?vfsStreamContainer
public static function getRoot(): ?vfsStreamDirectory
{
return self::$root;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php
Expand Up @@ -24,13 +24,13 @@ class vfsStreamPrintVisitor extends vfsStreamAbstractVisitor
/**
* target to write output to
*
* @type resource
* @var resource
*/
protected $out;
/**
* current depth in directory tree
*
* @type int
* @var int
*/
protected $depth = 0;

Expand Down
Expand Up @@ -24,13 +24,13 @@ class vfsStreamStructureVisitor extends vfsStreamAbstractVisitor
/**
* collected structure
*
* @type array
* @var array
*/
protected $structure = [];
/**
* poiting to currently iterated directory
*
* @type array
* @var array
*/
protected $current;

Expand Down