Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor/
build/
composer.lock
.phpunit.result.cache
.idea
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=8.0.0",
"ext-json":"*",
"regex-guard/regex-guard": "~1.0",
"nikic/php-parser" : ">=2.0 <5.0.0"
"nikic/php-parser" : "^5.0"
},
"require-dev": {
"mockery/mockery": "^0.9",
"phpunit/phpunit": ">=4.8 <6.0.0"
"mockery/mockery": "^1.6",
"phpunit/phpunit": ">=8.5.0"
},
"autoload": {
"psr-4": { "Minime\\Annotations\\": "src/" }
Expand Down
71 changes: 34 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,47 @@

<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
failOnWarning="true"
>

<testsuites>
<testsuite>
<testsuite name="annotation">
<directory>test/suite/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory>src/</directory>
</whitelist>
</filter>
<!-- <filter>-->
<!-- <whitelist processUncoveredFilesFromWhitelist="true">-->
<!-- <directory>src/</directory>-->
<!-- </whitelist>-->
<!-- </filter>-->

<logging>
<log
type="tap"
target="build/logs/report.tap"
/>
<log
type="junit"
target="build/logs/report.junit.xml"
/>
<log
type="coverage-html"
target="build/logs/coverage"
charset="UTF-8"
yui="true"
highlight="true"
/>
<log
type="coverage-text"
target="build/logs/coverage.txt"
/>
<log
type="coverage-clover"
target="build/logs/clover.xml"
/>
</logging>
<!-- <logging>-->
<!-- <log-->
<!-- type="tap"-->
<!-- target="build/logs/report.tap"-->
<!-- />-->
<!-- <log-->
<!-- type="junit"-->
<!-- target="build/logs/report.junit.xml"-->
<!-- />-->
<!-- <log-->
<!-- type="coverage-html"-->
<!-- target="build/logs/coverage"-->
<!-- charset="UTF-8"-->
<!-- yui="true"-->
<!-- highlight="true"-->
<!-- />-->
<!-- <log-->
<!-- type="coverage-text"-->
<!-- target="build/logs/coverage.txt"-->
<!-- />-->
<!-- <log-->
<!-- type="coverage-clover"-->
<!-- target="build/logs/clover.xml"-->
<!-- />-->
<!-- </logging>-->
</phpunit>
17 changes: 8 additions & 9 deletions src/AnnotationsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Minime\Annotations;

use Traversable;
use Minime\Annotations\Interfaces\AnnotationsBagInterface;
use RegexGuard\Factory as RegexGuard;
use ArrayIterator;
Expand Down Expand Up @@ -153,57 +154,55 @@ public function union(AnnotationsBagInterface $bag)
/**
* Countable
*/
public function count()
public function count() : int
{
return count($this->attributes);
}

/**
* JsonSerializable
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->toArray();
}

/**
* IteratorAggregate
*/
public function getIterator()
public function getIterator() : Traversable
{
return new ArrayIterator($this->attributes);
}

/**
* ArrayAccess - Whether or not an offset exists.
*/
public function offsetExists($key)
public function offsetExists($key): bool
{
return $this->has($key);
}

/**
* ArrayAccess - Returns the value at specified offset.
*/
public function offsetGet($key)
public function offsetGet($key) : mixed
{
return $this->get($key);
}

/**
* ArrayAccess - Assigns a value to the specified offset.
*/
public function offsetSet($key, $value)
public function offsetSet($key, $value): void
{
$this->set($key, $value);

return true;
}

/**
* ArrayAccess - Unsets an offset.
*/
public function offsetUnset($key)
public function offsetUnset($key) : void
{
unset($this->attributes[$key]);
}
Expand Down
20 changes: 11 additions & 9 deletions src/Cache/ApcCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,29 @@ public function getKey($docblock)

public function set($key, array $annotations)
{
if (! apc_exists($key)) {
apc_store($key, $annotations);
if (! apcu_exists($key)) {
apcu_store($key, $annotations);
}
}

public function get($key)
{
if (apc_exists($key)) {
return apc_fetch($key);
if (apcu_exists($key)) {
return apcu_fetch($key);
}

return [];
}

public function clear()
{
$cache = apc_cache_info('user');
foreach ($cache['cache_list'] as $entry) {
if(isset($entry['info'])
&& strpos($entry['info'], 'minime-annotations:') === 0) {
apc_delete($entry['info']);
$cache = apcu_cache_info();
if ($cache) {
foreach ($cache['cache_list'] as $entry) {
if(isset($entry['info'])
&& strpos($entry['info'], 'minime-annotations:') === 0) {
apcu_delete($entry['info']);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function getDocblockTagsSection($docblock)
* @param string $docblock A raw docblok string
* @return string A docblok string without delimiters
*/
protected function sanitizeDocblock($docblock)
protected function sanitizeDocblock(string $docblock)
{
return preg_replace('/\s*\*\/$|^\s*\*\s{0,1}|^\/\*{1,2}/m', '', $docblock);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getConstantAnnotations($class, $const)
*/
public function getAnnotations(\Reflector $Reflection)
{
$doc = $Reflection->getDocComment();
$doc = (string)$Reflection->getDocComment();
if ($this->cache) {
$key = $this->cache->getKey($doc);
$ast = $this->cache->get($key);
Expand Down
10 changes: 6 additions & 4 deletions src/Reflector/ReflectionConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Minime\Annotations\Reflector;

use PhpParser\PhpVersion;
use PhpParser\ParserFactory;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
Expand Down Expand Up @@ -34,17 +35,18 @@ public function __construct($class, $constName)
$className = $classReflection->getName();
$fileName = $classReflection->getFileName();

$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.0'));

try {
$stmts = $parser->parse(file_get_contents($fileName));
} catch (ParserError $e) {
throw new \ReflectionException("Cannot parse the class ${fileName}", 0, $e);
throw new \ReflectionException("Cannot parse the class {$fileName}", 0, $e);
}

// Class can be in a namespace or at the root of the statement
$classNode = $this->findClassNode($stmts);
if (!$classNode) {
throw new \ReflectionException("Class ${className} not found in file ${fileName}");
throw new \ReflectionException("Class {$className} not found in file {$fileName}");
}


Expand All @@ -62,7 +64,7 @@ public function __construct($class, $constName)
}

if (!$this->constNode) {
throw new \ReflectionException("Class constant ${constName} does not exist in class ${className}");
throw new \ReflectionException("Class constant {$constName} does not exist in class {$className}");
}

}
Expand Down
Loading