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

Added Nette\Utils\Future for lazy value evaluation #272

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
19 changes: 0 additions & 19 deletions .github/ISSUE_TEMPLATE/Bug_report.md

This file was deleted.

9 changes: 0 additions & 9 deletions .github/ISSUE_TEMPLATE/Feature_request.md

This file was deleted.

12 changes: 0 additions & 12 deletions .github/ISSUE_TEMPLATE/Support_question.md

This file was deleted.

21 changes: 0 additions & 21 deletions .github/ISSUE_TEMPLATE/Support_us.md

This file was deleted.

2 changes: 0 additions & 2 deletions .github/funding.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/pull_request_template.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
php: ['8.0', '8.1']

fail-fast: false

Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
extensions: iconv, json, mbstring, xml, gd, intl, tokenizer
coverage: none

Expand Down
6 changes: 3 additions & 3 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
expectedArguments(\Nette\Utils\Image::calculateSize(), 4, \Nette\Utils\Image::SHRINK_ONLY, \Nette\Utils\Image::STRETCH, \Nette\Utils\Image::FIT, \Nette\Utils\Image::FILL, \Nette\Utils\Image::EXACT);
expectedArguments(\Nette\Utils\Json::encode(), 1, \Nette\Utils\Json::PRETTY);
expectedArguments(\Nette\Utils\Json::decode(), 1, \Nette\Utils\Json::FORCE_ARRAY);
expectedArguments(\Nette\Utils\Strings::split(), 2, \PREG_SPLIT_NO_EMPTY);
expectedArguments(\Nette\Utils\Strings::match(), 2, \PREG_OFFSET_CAPTURE);
expectedArguments(\Nette\Utils\Strings::matchAll(), 2, \PREG_OFFSET_CAPTURE, \PREG_SET_ORDER);
expectedArguments(\Nette\Utils\Strings::split(), 2, \PREG_SPLIT_NO_EMPTY | \PREG_OFFSET_CAPTURE);
expectedArguments(\Nette\Utils\Strings::match(), 2, \PREG_OFFSET_CAPTURE | \PREG_UNMATCHED_AS_NULL);
expectedArguments(\Nette\Utils\Strings::matchAll(), 2, \PREG_OFFSET_CAPTURE | \PREG_UNMATCHED_AS_NULL | \PREG_PATTERN_ORDER);
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require": {
"php": ">=7.2 <8.2"
"php": ">=8.0 <8.2"
},
"require-dev": {
"nette/tester": "~2.0",
"tracy/tracy": "^2.3",
"nette/tester": "^2.4",
"tracy/tracy": "^2.8",
"phpstan/phpstan": "^0.12"
},
"conflict": {
Expand All @@ -44,7 +44,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "4.0-dev"
}
}
}
33 changes: 0 additions & 33 deletions contributing.md

This file was deleted.

2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


return function (Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(PRESET_DIR . '/php71.php');
$containerConfigurator->import(PRESET_DIR . '/php80.php');

$parameters = $containerConfigurator->parameters();

Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The recommended way to install is via Composer:
composer require nette/utils
```

- Nette Utils 4.0 is compatible with PHP 8.0 to 8.1
- Nette Utils 3.2 is compatible with PHP 7.2 to 8.1
- Nette Utils 3.1 is compatible with PHP 7.1 to 8.0
- Nette Utils 3.0 is compatible with PHP 7.1 to 8.0
Expand Down
11 changes: 4 additions & 7 deletions src/Iterators/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class CachingIterator extends \CachingIterator implements \Countable
{
use Nette\SmartObject;

/** @var int */
private $counter = 0;
private int $counter = 0;


public function __construct($iterator)
Expand All @@ -47,7 +46,7 @@ public function __construct($iterator)
} elseif ($iterator instanceof \Traversable) {
$iterator = new \IteratorIterator($iterator);
} else {
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? get_class($iterator) : gettype($iterator)));
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? $iterator::class : gettype($iterator)));
}

parent::__construct($iterator, 0);
Expand Down Expand Up @@ -147,19 +146,17 @@ public function rewind(): void

/**
* Returns the next key.
* @return mixed
*/
public function getNextKey()
public function getNextKey(): mixed
{
return $this->getInnerIterator()->key();
}


/**
* Returns the next element.
* @return mixed
*/
public function getNextValue()
public function getNextValue(): mixed
{
return $this->getInnerIterator()->current();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Iterators/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function __construct(\Traversable $iterator, callable $callback)
}


#[\ReturnTypeWillChange]
public function current()
public function current(): mixed
{
return ($this->callback)(parent::current(), parent::key());
}
Expand Down
39 changes: 25 additions & 14 deletions src/SmartObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait SmartObject
/**
* @throws MemberAccessException
*/
public function __call(string $name, array $args)
public function __call(string $name, array $args): mixed
{
$class = static::class;

Expand All @@ -37,35 +37,41 @@ public function __call(string $name, array $args)
} elseif ($handlers !== null) {
throw new UnexpectedValueException("Property $class::$$name must be iterable or null, " . gettype($handlers) . ' given.');
}

} else {
ObjectHelpers::strictCall($class, $name);
return null;
}

ObjectHelpers::strictCall($class, $name);
}


/**
* @throws MemberAccessException
*/
public static function __callStatic(string $name, array $args)
public static function __callStatic(string $name, array $args): mixed
{
ObjectHelpers::strictStaticCall(static::class, $name);
}


/**
* @return mixed
* @throws MemberAccessException if the property is not defined.
*/
public function &__get(string $name)
public function &__get(string $name): mixed
{
$class = static::class;

if ($prop = ObjectHelpers::getMagicProperties($class)[$name] ?? null) { // property getter
if (!($prop & 0b0001)) {
throw new MemberAccessException("Cannot read a write-only property $class::\$$name.");
}
$m = ($prop & 0b0010 ? 'get' : 'is') . $name;
$m = ($prop & 0b0010 ? 'get' : 'is') . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
if ($prop & 0b0100) { // return by reference
return $this->$m();
} else {
Expand All @@ -79,11 +85,9 @@ public function &__get(string $name)


/**
* @param mixed $value
* @return void
* @throws MemberAccessException if the property is not defined or is read-only
*/
public function __set(string $name, $value)
public function __set(string $name, mixed $value): void
{
$class = static::class;

Expand All @@ -94,7 +98,15 @@ public function __set(string $name, $value)
if (!($prop & 0b1000)) {
throw new MemberAccessException("Cannot write to a read-only property $class::\$$name.");
}
$this->{'set' . $name}($value);
$m = 'set' . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
$this->$m($value);

} else {
ObjectHelpers::strictSet($class, $name);
Expand All @@ -103,10 +115,9 @@ public function __set(string $name, $value)


/**
* @return void
* @throws MemberAccessException
*/
public function __unset(string $name)
public function __unset(string $name): void
{
$class = static::class;
if (!ObjectHelpers::hasProperty($class, $name)) {
Expand Down
3 changes: 1 addition & 2 deletions src/StaticClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ final public function __construct()

/**
* Call to undefined static method.
* @return void
* @throws MemberAccessException
*/
public static function __callStatic(string $name, array $args)
public static function __callStatic(string $name, array $args): mixed
{
Utils\ObjectHelpers::strictStaticCall(static::class, $name);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ interface Translator
{
/**
* Translates the given string.
* @param mixed $message
* @param mixed ...$parameters
*/
function translate($message, ...$parameters): string;
function translate(string|\Stringable $message, mixed ...$parameters): string|\Stringable;
}


Expand Down
6 changes: 2 additions & 4 deletions src/Utils/ArrayHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class ArrayHash extends \stdClass implements \ArrayAccess, \Countable, \Iterator
/**
* Transforms array to ArrayHash.
* @param array<T> $array
* @return static
*/
public static function from(array $array, bool $recursive = true)
public static function from(array $array, bool $recursive = true): static
{
$obj = new static;
foreach ($array as $key => $value) {
Expand Down Expand Up @@ -73,8 +72,7 @@ public function offsetSet($key, $value): void
* @param string|int $key
* @return T
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($key): mixed
{
return $this->$key;
}
Expand Down
Loading