Skip to content

Commit

Permalink
Merge pull request #463 from goaop/feature/php-74-property-types-phpstan
Browse files Browse the repository at this point in the history
[Feature] PHP7.4 property types, PHPStan introduction
  • Loading branch information
lisachenko committed Jan 4, 2021
2 parents 1e173c0 + 8acc950 commit 5a69ec8
Show file tree
Hide file tree
Showing 220 changed files with 2,139 additions and 1,784 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "PHPStan analysis"

on:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
ini-values: memory_limit=-1
tools: composer:v2
- name: "Cache dependencies"
uses: actions/cache@v2
with:
path: |
~/.composer/cache
vendor
key: "php-7.4"
restore-keys: "php-7.4"
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Static analysis"
uses: chindit/actions-phpstan@master
9 changes: 5 additions & 4 deletions bin/aspect
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env php
<?php

declare(strict_types = 1);
/*
* Go! AOP framework
Expand All @@ -10,11 +11,11 @@ declare(strict_types = 1);
* with this source code in the file LICENSE.
*/

use Composer\InstalledVersions;
use Go\Console\Command\CacheWarmupCommand;
use Go\Console\Command\DebugAdvisorCommand;
use Go\Console\Command\DebugAspectCommand;
use Go\Console\Command\CacheWarmupCommand;
use Go\Console\Command\DebugWeavingCommand;
use Go\Core\AspectKernel;
use Symfony\Component\Console\Application;


Expand All @@ -31,14 +32,14 @@ if (is_dir($vendor = __DIR__ . '/../vendor')) {
);
}

if (!class_exists('Symfony\Component\Console\Application')) {
if (!class_exists(Application::class)) {
die(
'You must install the symfony/console package in order ' .
'to use the command-line tool.' . PHP_EOL
);
}

$app = new Application('Go! AOP', AspectKernel::VERSION);
$app = new Application('Go! AOP', InstalledVersions::getVersion('goaop/framework'));
$app->add(new CacheWarmupCommand());
$app->add(new DebugAspectCommand());
$app->add(new DebugAdvisorCommand());
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php": "^7.4.0",
"doctrine/annotations": "^1.11.1",
"doctrine/cache": "^1.10",
"goaop/parser-reflection": "^3.0",
"goaop/parser-reflection": "^3.0.1",
"jakubledl/dissect": "~1.0",
"laminas/laminas-code": "^4.0",
"symfony/finder": "^4.4|^5.1"
Expand All @@ -20,6 +20,7 @@
"require-dev": {
"adlawson/vfs": "^0.12.1",
"doctrine/orm": "^2.5",
"phpstan/phpstan": "^0.12.64",
"phpunit/phpunit": "^9.5",
"symfony/console": "^4.4|^5.1",
"symfony/filesystem": "^4.4|^5.1",
Expand Down
7 changes: 3 additions & 4 deletions demos/Demo/Annotation/Cacheable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -21,8 +22,6 @@ class Cacheable extends Annotation
{
/**
* Time to cache
*
* @var int
*/
public $time = 0;
public int $time = 0;
}
4 changes: 2 additions & 2 deletions demos/Demo/Annotation/Deprecated.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -19,5 +20,4 @@
*/
class Deprecated extends Annotation
{

}
4 changes: 2 additions & 2 deletions demos/Demo/Annotation/Loggable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -19,5 +20,4 @@
*/
class Loggable extends Annotation
{

}
9 changes: 4 additions & 5 deletions demos/Demo/Aspect/AwesomeAspectKernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -11,8 +12,8 @@

namespace Demo\Aspect;

use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
use Go\Core\AspectKernel;

/**
* Awesome Aspect Kernel class
Expand All @@ -21,10 +22,8 @@ class AwesomeAspectKernel extends AspectKernel
{
/**
* Configure an AspectContainer with advisors, aspects and pointcuts
*
* @param AspectContainer $container
*/
protected function configureAop(AspectContainer $container)
protected function configureAop(AspectContainer $container): void
{
$container->registerAspect(new DeclareErrorAspect());
$container->registerAspect(new CachingAspect());
Expand Down
12 changes: 6 additions & 6 deletions demos/Demo/Aspect/CachingAspect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -11,6 +12,7 @@

namespace Demo\Aspect;

use Demo\Annotation\Cacheable;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Around;
Expand All @@ -28,24 +30,22 @@ class CachingAspect implements Aspect
*
* Real-life examples will use APC or Memcache to store value in the cache
*
* @param MethodInvocation $invocation Invocation
* @return mixed Result of invocation
*
* @Around("@execution(Demo\Annotation\Cacheable)")
*/
public function aroundCacheable(MethodInvocation $invocation)
{
static $memoryCache = [];

$time = microtime(true);
$time = microtime(true);

$obj = $invocation->getThis();
$class = is_object($obj) ? get_class($obj) : $obj;
$key = $class . ':' . $invocation->getMethod()->name;
if (!isset($memoryCache[$key])) {
// We can use ttl value from annotation, but Doctrine annotations doesn't work under GAE
if (!isset($_SERVER['APPENGINE_RUNTIME'])) {
echo "Ttl is: ", $invocation->getMethod()->getAnnotation('Demo\Annotation\Cacheable')->time, PHP_EOL;
}
echo "Ttl is: ", $invocation->getMethod()->getAnnotation(Cacheable::class)->time, PHP_EOL;

$memoryCache[$key] = $invocation->proceed();
}
Expand Down
9 changes: 4 additions & 5 deletions demos/Demo/Aspect/DeclareErrorAspect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -22,16 +23,14 @@ class DeclareErrorAspect implements Aspect
/**
* Message to show when calling the method
*
* @var string
* @DeclareError("@execution(Demo\Annotation\Deprecated)", level=16384) // E_USER_DEPRECATED
*/
protected $message = 'Method is deprecated and should not be called in debug mode';
protected string $message = 'Method is deprecated and should not be called in debug mode';

/**
* Prevent developers from using this method by always generating a warning
*
* @var string
* @DeclareError("execution(public Demo\Example\ErrorDemo->notSoGoodMethod(*))", level=512) // E_USER_WARNING
*/
protected $badMethod = 'Method can generate division by zero! Do not use it!';
protected string $badMethod = 'Method can generate division by zero! Do not use it!';
}
14 changes: 6 additions & 8 deletions demos/Demo/Aspect/DynamicMethodsAspect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -20,21 +21,18 @@
*/
class DynamicMethodsAspect implements Aspect
{

/**
* This advice intercepts an execution of __call methods
*
* Unlike traditional "execution" pointcut, "dynamic" is checking the name of method in
* the runtime, allowing to write interceptors for __call more transparently.
*
* @param MethodInvocation $invocation Invocation
*
* @Before("dynamic(public Demo\Example\DynamicMethodsDemo->save*(*))")
*/
public function beforeMagicMethodExecution(MethodInvocation $invocation)
public function beforeMagicMethodExecution(MethodInvocation $invocation): void
{
// we need to unpack args from invocation args
list($methodName, $args) = $invocation->getArguments();
[$methodName, $args] = $invocation->getArguments();
echo 'Calling Magic Interceptor for method: ',
$invocation->getScope(),
'->',
Expand All @@ -51,10 +49,10 @@ public function beforeMagicMethodExecution(MethodInvocation $invocation)
* @param MethodInvocation $invocation
* @Before("dynamic(public Demo\Example\DynamicMethodsDemo::find*(*))")
*/
public function beforeMagicStaticMethodExecution(MethodInvocation $invocation)
public function beforeMagicStaticMethodExecution(MethodInvocation $invocation): void
{
// we need to unpack args from invocation args
list($methodName, $args) = $invocation->getArguments();
[$methodName, $args] = $invocation->getArguments();
echo 'Calling Static Magic Interceptor for method: ',
$invocation->getScope(),
'::',
Expand Down
4 changes: 2 additions & 2 deletions demos/Demo/Aspect/FluentInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -16,5 +17,4 @@
*/
interface FluentInterface
{

}
6 changes: 3 additions & 3 deletions demos/Demo/Aspect/FluentInterfaceAspect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand Down Expand Up @@ -31,8 +32,7 @@ class FluentInterfaceAspect implements Aspect
*
* @Around("within(Demo\Aspect\FluentInterface+) && execution(public **->set*(*))")
*
* @param MethodInvocation $invocation
* @return mixed|null|object
* @return mixed Result of invocation
*/
protected function aroundMethodExecution(MethodInvocation $invocation)
{
Expand Down
12 changes: 3 additions & 9 deletions demos/Demo/Aspect/FunctionInterceptorAspect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
/*
* Go! AOP framework
*
Expand All @@ -20,12 +21,9 @@
*/
class FunctionInterceptorAspect implements Aspect
{

/**
* This advice intercepts an access to the array_*** function in Demo\Example\ namespace
*
* @param FunctionInvocation $invocation
*
* @Around("execution(Demo\Example\array_*(*))")
*
* @return mixed
Expand All @@ -44,13 +42,9 @@ public function aroundArrayFunctions(FunctionInvocation $invocation)
/**
* This advice intercepts an access to the file_get_contents() function
*
* @param FunctionInvocation $invocation
*
* @Around("execution(Demo\Example\file_get_contents(*))")
*
* @return mixed
*/
public function aroundFileGetContents(FunctionInvocation $invocation)
public function aroundFileGetContents(FunctionInvocation $invocation): string
{
echo 'Calling Around Interceptor for ',
$invocation,
Expand Down

0 comments on commit 5a69ec8

Please sign in to comment.