Skip to content

Commit

Permalink
Merge pull request #43 from wick-ed/hotfix/1098
Browse files Browse the repository at this point in the history
Removed buffered read-in of structures to find identifier
  • Loading branch information
wick-ed committed Jul 18, 2018
2 parents 7744c22 + dd41908 commit 0dc2419
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 66 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# Version 1.7.1

## Bugfixes

* Fixed bug with building up the structure map and structure names that fall on the read-in buffer size

## Features

* None

# Version 1.7.0

## Bugfixes

* None

## Features

* Allowed importing assertion type namespaces with the `use` statement

# Version 1.6.0

## Bugfixes

* None

## Features

* Allowed usage of fully qualified class names of assertions with condition types

# Version 1.5.1

## Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion build.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#--------------------------------------------------------------------------------

# ---- Module Release Settings --------------------------------------------------
release.version = 1.5.0
release.version = 1.7.1

# ---- PHPCPD Settings ----------------------------------------------------------
# Directories
Expand Down
115 changes: 50 additions & 65 deletions src/StructureMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,85 +688,70 @@ protected function findAnnotations($file, array $annotations)
protected function findIdentifier($file)
{

$rsc = fopen($file, 'r');
$code = file_get_contents($file);

// if we could not open the file tell them
if ($rsc === false) {
if ($code === false) {
throw new ParserException(sprintf('Could not open file %s for type inspection.', $file));
}

// some variables we will need
$buffer = '';
$namespace = '';
$type = '';
$stuctureName = '';

// get the buffer step by step
for ($k = 0; $k < 20; $k++) {
// clear collected things on every iteration, so we will not chain them on in case of several needed loops
$namespace = '';

// break if we reached the end of the file
if (feof($rsc)) {
break;
}

// fill the buffer piece by piece
$buffer .= fread($rsc, 2048);

// get the tokens and their count
$tokens = @token_get_all($buffer);
$count = count($tokens);

// iterate over the current set of tokens and filter out what we found
for ($i = 0; $i < $count; $i++) {
if ($tokens[$i][0] == T_NAMESPACE) {
// we passed the namespace token, lets collect the name
for ($j = $i; $j < $count; $j++) {
if ($tokens[$j][0] === T_STRING) {
// collect all strings and connect them
$namespace .= '\\' . $tokens[$j][1];

} elseif ($tokens[$j] === '{' || $tokens[$j] === ';') {
// break if we clearly reached the end of the namespace declaration
break;
}
// get the tokens and their count
$tokens = @token_get_all($code);
$count = count($tokens);

// iterate over the current set of tokens and filter out what we found
for ($i = 0; $i < $count; $i++) {
if ($tokens[$i][0] == T_NAMESPACE) {
// we passed the namespace token, lets collect the name
for ($j = $i; $j < $count; $j++) {
if ($tokens[$j][0] === T_STRING) {
// collect all strings and connect them
$namespace .= '\\' . $tokens[$j][1];

} elseif ($tokens[$j] === '{' || $tokens[$j] === ';') {
// break if we clearly reached the end of the namespace declaration
break;
}
}
continue;

continue;
} elseif ($i > 1
&& $tokens[$i - 2][0] === T_CLASS
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
if ($this->findAnnotations($file, array(Aspect::ANNOTATION))) {
$type = 'aspect';

} elseif ($i > 1
&& $tokens[$i - 2][0] === T_CLASS
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
if ($this->findAnnotations($file, array(Aspect::ANNOTATION))) {
$type = 'aspect';
} else {
$type = 'class';
}

} else {
$type = 'class';
}
$stuctureName = $tokens[$i][1];
break;

$stuctureName = $tokens[$i][1];
break 2;

} elseif ($i > 1
&& $tokens[$i - 2][0] === T_TRAIT
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
$type = 'trait';
$stuctureName = $tokens[$i][1];
break 2;

} elseif ($i > 1
&& $tokens[$i - 2][0] === T_INTERFACE
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
$type = 'interface';
$stuctureName = $tokens[$i][1];
break 2;
}
} elseif ($i > 1
&& $tokens[$i - 2][0] === T_TRAIT
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
$type = 'trait';
$stuctureName = $tokens[$i][1];
break;

} elseif ($i > 1
&& $tokens[$i - 2][0] === T_INTERFACE
&& $tokens[$i - 1][0] === T_WHITESPACE
&& $tokens[$i][0] === T_STRING
) {
$type = 'interface';
$stuctureName = $tokens[$i][1];
break;
}
}

Expand Down

0 comments on commit 0dc2419

Please sign in to comment.