Skip to content

Commit

Permalink
Merge pull request #2302 from zephir-lang/#2272-fix-bool-return-type-…
Browse files Browse the repository at this point in the history
…stubs

Mass code refactor
  • Loading branch information
AlexNDRmac authored Oct 5, 2021
2 parents 5f93497 + 9e0920f commit 2ba1348
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 190 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:

- name: Setup PHP
uses: shivammathur/setup-php@v2
env:
PHP_CS_FIXER_VERSION: 3.2.0
with:
php-version: '7.4'
coverage: none
tools: php-cs-fixer, phpcs
tools: php-cs-fixer:${{ env.PHP_CS_FIXER_VERSION }}, phpcs

- name: Run PHP_CodeSniffer
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org).
## [Unreleased]
### Fixed
- Fixed multiple return types in stubs [#2283](https://github.com/zephir-lang/zephir/issues/2283)
- Fixed `bool` return type in stubs [#2272](https://github.com/zephir-lang/zephir/issues/2272)

### Changed
- Removed `.zep` from stubs filenames [#2273](https://github.com/zephir-lang/zephir/issues/2273)

Expand Down
72 changes: 32 additions & 40 deletions Library/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,53 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir;

use Zephir\Statements\StatementAbstract;

/**
* Branch.
*
* Represents every branch within a method
*/
class Branch
{
const TYPE_ROOT = 0;

const TYPE_CONDITIONAL_TRUE = 1;

const TYPE_CONDITIONAL_FALSE = 2;

const TYPE_LOOP_INFINITE = 3;

const TYPE_LOOP_CONDITIONAL = 4;

const TYPE_SWITCH = 5;

const TYPE_EXTERNAL = 6;

const TYPE_UNKNOWN = 7;
protected $parentBranch;

protected $level = -1;

/** @var StatementAbstract|null */
protected $relatedStatement;

protected $type;

protected $unreachable;
public const TYPE_ROOT = 0;
public const TYPE_CONDITIONAL_TRUE = 1;
public const TYPE_CONDITIONAL_FALSE = 2;
public const TYPE_LOOP_INFINITE = 3;
public const TYPE_LOOP_CONDITIONAL = 4;
public const TYPE_SWITCH = 5;
public const TYPE_EXTERNAL = 6;
public const TYPE_UNKNOWN = 7;

protected int $level = -1;
protected int $type = self::TYPE_ROOT;
protected bool $unreachable = false;
protected ?Branch $parentBranch = null;
protected ?StatementAbstract $relatedStatement = null;

/**
* @var mixed
*/
private $uniqueId;

/**
* Set the branch's parent.
*
* @param Branch $parentBranch
*/
public function setParentBranch(self $parentBranch)
public function setParentBranch(self $parentBranch): void
{
$this->parentBranch = $parentBranch;
}

/**
* Returns the branch's parent.
*
* @return Branch
* @return Branch|null
*/
public function getParentBranch()
public function getParentBranch(): ?self
{
return $this->parentBranch;
}
Expand All @@ -73,7 +65,7 @@ public function getParentBranch()
*
* @param int $type
*/
public function setType($type)
public function setType(int $type): void
{
$this->type = $type;
}
Expand All @@ -83,7 +75,7 @@ public function setType($type)
*
* @return int
*/
public function getType()
public function getType(): int
{
return $this->type;
}
Expand All @@ -93,31 +85,31 @@ public function getType()
*
* @param bool $unreachable
*/
public function setUnreachable($unreachable)
public function setUnreachable(bool $unreachable): void
{
$this->unreachable = $unreachable;
}

/**
* @return mixed
* @return bool
*/
public function isUnreachable()
public function isUnreachable(): bool
{
return $this->unreachable;
}

/**
* @param $level
* @param int $level
*/
public function setLevel($level)
public function setLevel(int $level): void
{
$this->level = $level;
}

/**
* @return int
*/
public function getLevel()
public function getLevel(): int
{
return $this->level;
}
Expand All @@ -141,15 +133,15 @@ public function getUniqueId()
/**
* @param StatementAbstract $relatedStatement
*/
public function setRelatedStatement(StatementAbstract $relatedStatement)
public function setRelatedStatement(StatementAbstract $relatedStatement): void
{
$this->relatedStatement = $relatedStatement;
}

/**
* @return StatementAbstract|null
*/
public function getRelatedStatement()
public function getRelatedStatement(): ?StatementAbstract
{
return $this->relatedStatement;
}
Expand Down
3 changes: 1 addition & 2 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use function count;
use function gettype;
use function is_array;
use function strlen;
use const DIRECTORY_SEPARATOR;

/**
Expand Down Expand Up @@ -526,7 +525,7 @@ public function getParsedDocBlock(): ?DocBlock
return $this->parsedDocblock;
}

if (strlen($this->docBlock) === 0) {
if ($this->docBlock === '') {
return null;
}

Expand Down
3 changes: 1 addition & 2 deletions Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Zephir\FileSystem\FileSystemInterface;

use function is_array;
use function strlen;

/**
* Zephir\CompilerFile.
Expand Down Expand Up @@ -484,7 +483,7 @@ public function preCompile(Compiler $compiler)
foreach ($ir as $topStatement) {
switch ($topStatement['type']) {
case 'namespace':
if (strlen($namespace) > 0) {
if ($namespace !== '') {
throw new CompilerException('The namespace must be defined just one time', $topStatement);
}

Expand Down
6 changes: 3 additions & 3 deletions Library/Documentation/DocblockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(string $annotation)
*/
private function __tryRegisterAnnotation()
{
if (($this->annotationNameOpen || $this->annotationOpen) && \strlen($this->currentAnnotationStr) > 0) {
if (($this->annotationNameOpen || $this->annotationOpen) && $this->currentAnnotationStr !== '') {
$annotation = $this->__createAnnotation($this->currentAnnotationStr, $this->currentAnnotationContentStr);
$this->docblockObj->addAnnotation($annotation);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public function parse()

if ('@' == $currentChar) {
$this->descriptionStr = trim($this->descriptionStr);
if ($this->descriptionOpen && \strlen($this->descriptionStr) > 0) {
if ($this->descriptionOpen && $this->descriptionStr !== '') {
$this->descriptionOpen = false;
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public function parse()
}
} elseif ($this->summaryOpen) {
// stop summary on new line
if (\strlen($this->summaryStr) > 0 && ("\n" == $currentChar || "\r" == $currentChar)) {
if ($this->summaryStr !== '' && ("\n" == $currentChar || "\r" == $currentChar)) {
$this->summaryOpen = false;
$this->descriptionOpen = true;
$this->ignoreStar = true;
Expand Down
2 changes: 1 addition & 1 deletion Library/Documentation/File/ClassFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getData(): array
$nsStr = '';

foreach ($nsPieces as $n) {
if (\strlen($nsStr) > 0) {
if ($nsStr !== '') {
$nsStr .= '\\';
}
$nsStr .= $n;
Expand Down
2 changes: 1 addition & 1 deletion Library/Documentation/NamespaceAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function build()
$ns = explode('\\', $class->getClassDefinition()->getNamespace());
$actualStr = '';
foreach ($ns as $n) {
if (\strlen($actualStr) > 0) {
if ($actualStr !== '') {
$previous = $byNamespace[$actualStr];
$actualStr .= '\\';
$isRoot = false;
Expand Down
Loading

0 comments on commit 2ba1348

Please sign in to comment.