Skip to content

Commit

Permalink
Add ALL THE TYPES (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Mar 13, 2019
1 parent 5bee82f commit 1f453a3
Show file tree
Hide file tree
Showing 90 changed files with 427 additions and 393 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

### Changed

- Pretty much everything now has parameter and return types (#346)
- `Environment` is now a `final` class
- `Environment::getBlockRendererForClass()` was replaced with `Environment::getBlockRenderersForClass()` (note the added `s`)
- `Environment::getInlineRendererForClass()` was replaced with `Environment::getInlineRenderersForClass()` (note the added `s`)
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ After doing this, the two abstract classes mentioned above had notthing left in

Several previously-deprecated methods inside of `RegexHelper` were finally removed. That functionality was made available with static methods and constants, so use those instead.

### Parameter and return types

Pretty much every method now uses parameter and return types, including several interfaces. Update your implementations accordingly.

### Environment interfaces

We have extracted two interfaces from the `Environment` class:
Expand Down
43 changes: 24 additions & 19 deletions src/Block/Element/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ protected function setParent(Node $node = null)
/**
* @return bool
*/
public function isContainer()
public function isContainer(): bool
{
return true;
}

/**
* @return bool
*/
public function hasChildren()
public function hasChildren(): bool
{
return $this->firstChild !== null;
}
Expand All @@ -104,28 +104,28 @@ public function hasChildren()
*
* @return bool
*/
abstract public function canContain(AbstractBlock $block);
abstract public function canContain(AbstractBlock $block): bool;

/**
* Returns true if block type can accept lines of text
*
* @return bool
*/
abstract public function acceptsLines();
abstract public function acceptsLines(): bool;

/**
* Whether this is a code block
*
* @return bool
*/
abstract public function isCode();
abstract public function isCode(): bool;

/**
* @param Cursor $cursor
*
* @return bool
*/
abstract public function matchesNextLine(Cursor $cursor);
abstract public function matchesNextLine(Cursor $cursor): bool;

/**
* @param ContextInterface $context
Expand All @@ -144,7 +144,7 @@ public function handleRemainingContents(ContextInterface $context, Cursor $curso
*
* @return $this
*/
public function setStartLine($startLine)
public function setStartLine(int $startLine)
{
$this->startLine = $startLine;
if (empty($this->endLine)) {
Expand All @@ -157,12 +157,17 @@ public function setStartLine($startLine)
/**
* @return int
*/
public function getStartLine()
public function getStartLine(): int
{
return $this->startLine;
}

public function setEndLine($endLine)
/**
* @param int $endLine
*
* @return $this
*/
public function setEndLine(int $endLine)
{
$this->endLine = $endLine;

Expand All @@ -172,7 +177,7 @@ public function setEndLine($endLine)
/**
* @return int
*/
public function getEndLine()
public function getEndLine(): int
{
return $this->endLine;
}
Expand All @@ -182,15 +187,15 @@ public function getEndLine()
*
* @return bool
*/
public function endsWithBlankLine()
public function endsWithBlankLine(): bool
{
return $this->lastLineBlank;
}

/**
* @param bool $blank
*/
public function setLastLineBlank($blank)
public function setLastLineBlank(bool $blank)
{
$this->lastLineBlank = $blank;
}
Expand All @@ -203,23 +208,23 @@ public function setLastLineBlank($blank)
*
* @return bool
*/
public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber)
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
{
return $cursor->isBlank();
}

/**
* @return string[]
*/
public function getStrings()
public function getStrings(): iterable
{
return $this->strings->toArray();
}

/**
* @param string $line
*/
public function addLine($line)
public function addLine(string $line)
{
if (!$this->acceptsLines()) {
throw new \LogicException('You cannot add lines to a block which cannot accept them');
Expand All @@ -233,7 +238,7 @@ public function addLine($line)
*
* @return bool
*/
public function isOpen()
public function isOpen(): bool
{
return $this->open;
}
Expand All @@ -244,7 +249,7 @@ public function isOpen()
* @param ContextInterface $context
* @param int $endLineNumber
*/
public function finalize(ContextInterface $context, $endLineNumber)
public function finalize(ContextInterface $context, int $endLineNumber)
{
if (!$this->open) {
return;
Expand All @@ -259,7 +264,7 @@ public function finalize(ContextInterface $context, $endLineNumber)
/**
* @return string
*/
public function getStringContent()
public function getStringContent(): string
{
return $this->finalStringContents;
}
Expand All @@ -270,7 +275,7 @@ public function getStringContent()
*
* @return mixed
*/
public function getData($key, $default = null)
public function getData(string $key, $default = null)
{
return array_key_exists($key, $this->data) ? $this->data[$key] : $default;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Block/Element/BlockQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BlockQuote extends AbstractBlock
*
* @return bool
*/
public function canContain(AbstractBlock $block)
public function canContain(AbstractBlock $block): bool
{
return true;
}
Expand All @@ -35,7 +35,7 @@ public function canContain(AbstractBlock $block)
*
* @return bool
*/
public function acceptsLines()
public function acceptsLines(): bool
{
return false;
}
Expand All @@ -45,12 +45,12 @@ public function acceptsLines()
*
* @return bool
*/
public function isCode()
public function isCode(): bool
{
return false;
}

public function matchesNextLine(Cursor $cursor)
public function matchesNextLine(Cursor $cursor): bool
{
if (!$cursor->isIndented() && $cursor->getNextNonSpaceCharacter() === '>') {
$cursor->advanceToNextNonSpaceOrTab();
Expand All @@ -69,7 +69,7 @@ public function matchesNextLine(Cursor $cursor)
*
* @return bool
*/
public function shouldLastLineBeBlank(Cursor $cursor, $currentLineNumber)
public function shouldLastLineBeBlank(Cursor $cursor, int $currentLineNumber): bool
{
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Block/Element/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
/**
* @return ReferenceMap
*/
public function getReferenceMap()
public function getReferenceMap(): ReferenceMap
{
return $this->referenceMap;
}
Expand All @@ -48,7 +48,7 @@ public function getReferenceMap()
*
* @return bool
*/
public function canContain(AbstractBlock $block)
public function canContain(AbstractBlock $block): bool
{
return true;
}
Expand All @@ -58,7 +58,7 @@ public function canContain(AbstractBlock $block)
*
* @return bool
*/
public function acceptsLines()
public function acceptsLines(): bool
{
return false;
}
Expand All @@ -68,12 +68,12 @@ public function acceptsLines()
*
* @return bool
*/
public function isCode()
public function isCode(): bool
{
return false;
}

public function matchesNextLine(Cursor $cursor)
public function matchesNextLine(Cursor $cursor): bool
{
return true;
}
Expand Down
Loading

0 comments on commit 1f453a3

Please sign in to comment.