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

Add phpstan to project #29

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ jobs:

- name: "Run code-style check"
run: composer phpcs

- name: "Run PHPStan check"
run: composer phpstan
166 changes: 0 additions & 166 deletions Cache/Memcache.php

This file was deleted.

8 changes: 4 additions & 4 deletions Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public function mSetNx($v)
return $result;
}

public function expire($key, $expire)
public function expire($key, $expire, $mode = null)
{
if ($this->stopwatch) {
$e = $this->getStopwatchEvent('expire');
}

$result = parent::expire($key, $expire);
$result = parent::expire($key, $expire, $mode);

if ($this->stopwatch) {
$e->stop();
Expand Down Expand Up @@ -192,13 +192,13 @@ public function sMembers($key)
return $result;
}

public function sAdd($tag, $id)
public function sAdd($tag, $id, ...$other_values)
{
if ($this->stopwatch) {
$e = $this->getStopwatchEvent('sAdd');
}

$result = parent::sAdd($tag, $id);
$result = parent::sAdd($tag, $id, ...$other_values);

if ($this->stopwatch) {
$e->stop();
Expand Down
4 changes: 3 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public function getConfigTreeBuilder(): TreeBuilder
$treeBuilder = new TreeBuilder('intaro_pinba');
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
} elseif (\method_exists($treeBuilder, 'root')) {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('intaro_pinba');
} else {
throw new \RuntimeException('Unsupported symfony/config version');
}

$rootNode
Expand Down
4 changes: 2 additions & 2 deletions EventListener/ScriptNameConfigureListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function onRequest(KernelEvent $event): void
pinba_script_name_set($event->getRequest()->getRequestUri());
}

private static function bcEvent($event)
private static function bcEvent($event): bool
{
$eventClass = \Symfony\Component\HttpKernel\Event\GetResponseEvent::class;
$eventClass = 'Symfony\Component\HttpKernel\Event\GetResponseEvent';

return class_exists($eventClass) && !$event instanceof $eventClass;
}
Expand Down
4 changes: 1 addition & 3 deletions IntaroPinbaBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class IntaroPinbaBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
if(Kernel::MAJOR_VERSION >= 3) {
$container->addCompilerPass(new TwigPass());
}
$container->addCompilerPass(new TwigPass());
}
}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ vendor: composer.json
phpcs: $(PHP_CONSOLE_DEPS)
@$(PHP) vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no -v

phpstan: $(PHP_CONSOLE_DEPS)
@$(PHP) vendor/bin/phpstan analyse

phpunit: $(PHP_CONSOLE_DEPS)
@$(PHP) vendor/bin/phpunit --color=always

check: phpcs phpunit
check: phpcs phpstan phpunit
44 changes: 2 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PinbaBundle is Symfony bundle for [pinba](http://pinba.org).

Important! Include this bundle only in `prod` environment.

It collects and sends times of execution for Doctrine queries, Twig renders and Memcache requests as pinba timers to pinba server. You can watch collected realtime metrics in [Intaro Pinboard](http://intaro.github.io/pinboard/). Example of output:
It collects and sends times of execution for Doctrine queries, Twig renders and Redis requests as pinba timers to pinba server. You can watch collected realtime metrics in [Intaro Pinboard](http://intaro.github.io/pinboard/). Example of output:

![Pinba timers in Intaro Pinboard](http://intaro.github.io/pinboard/img/timers.png)

Expand Down Expand Up @@ -73,46 +73,6 @@ doctrine:

Don't worry. This config enables pinba logger which collects only queries execution time but not logs them.

### Collecting Memcache metrics ###

PinbaBundle supplies Memcache wrapped class `Intaro\PinbaBundle\Cache\Memcache` which collects execution times of all memcache queries.

Example of `app/config/config_prod.yml`:
```yml
services:
memcache.db:
class: Intaro\PinbaBundle\Cache\Memcache
calls:
- [ addServer, [ %memcache.host%, %memcache.port% ]]
- [ setStopwatch, [ @intaro_pinba.stopwatch ]]
doctrine.metadata.memcache:
class: Doctrine\Common\Cache\MemcacheCache
calls:
- [ setMemcache, [ @memcache.db ]]
doctrine.query.memcache:
class: Doctrine\Common\Cache\MemcacheCache
calls:
- [ setMemcache, [ @memcache.db ]]
doctrine.result.memcache:
class: Doctrine\Common\Cache\MemcacheCache
calls:
- [ setMemcache, [ @memcache.db ]]

doctrine:
orm:
entity_managers:
default:
metadata_cache_driver:
type: service
id: doctrine.metadata.memcache
query_cache_driver:
type: service
id: doctrine.query.memcache
result_cache_driver:
type: service
id: doctrine.result.memcache
```

## Development ##

### Run tests ###
Expand All @@ -122,7 +82,7 @@ Install vendors:
make vendor
```

Run php-cs-fixer and phpunit:
Run php-cs-fixer, phpstan and phpunit:
```shell
make check
```
4 changes: 1 addition & 3 deletions Stopwatch/Stopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function start(array $tags)
$tags = array_merge($this->initTags, $tags);
if (isset($tags['group']) && !isset($tags['category']) && false !== strpos($tags['group'], '::')) {
$v = explode('::', $tags['group']);
if (count($v) > 0) {
$tags['category'] = $v[0];
}
$tags['category'] = $v[0];
}
}

Expand Down
2 changes: 2 additions & 0 deletions Twig/TimedTwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TimedTwigEngine extends TwigEngine
*/
public function __construct(\Twig\Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch)
{
/* @phpstan-ignore-next-line */
parent::__construct($environment, $parser, $locator);

$this->stopwatch = $stopwatch;
Expand All @@ -53,6 +54,7 @@ public function render($name, array $parameters = [])
'twig_template' => (string) $name,
]);

/* @phpstan-ignore-next-line */
$ret = parent::render($name, $parameters);

$e->stop();
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intaro/pinba-bundle",
"description": "Collects and sends execution time of Doctrine queries, Twig renders and Memcache requests as pinba timers to pinba server",
"description": "Collects and sends execution time of Doctrine queries, Twig renders and Redis requests as pinba timers to pinba server",
"keywords": ["symfony", "pinba", "php"],
"type": "symfony-bundle",
"license": "MIT",
Expand All @@ -13,6 +13,7 @@
"symfony/yaml": "^4.0|^5.0|^6.0"
},
"require-dev": {
"doctrine/dbal": "^2|^3|^4",
"nyholm/symfony-bundle-test": "^2.0",
"phpunit/phpunit": "^8.5|^9.5",
"symfony/phpunit-bridge": "^5.0|^6.0",
Expand All @@ -27,14 +28,16 @@
"symfony/routing": "^4.4|^5.0|^6.0",
"symfony/finder": "^4.4|^5.0|^6.0",
"symfony/filesystem": "^4.4|^5.0|^6.0",
"symfony/templating": "^4.4|^5.0|^6.0",
"symfony/translation-contracts": "^1.1|^2.0",
"symfony/var-exporter": "^4.4|^5.0|^6.0",
"symfony/var-dumper": "^4.4|^5.0|^6.0",
"psr/log": "~1.0|^2|^3",
"friendsofphp/php-cs-fixer": "3.4",
"twig/twig": "^v2.14 || ^3.0",
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
"symfony/twig-bridge": "^4.4|^5.0|^6.0"
"symfony/twig-bridge": "^4.4|^5.0|^6.0",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand All @@ -51,7 +54,6 @@
"phpcs": [
"vendor/bin/php-cs-fixer fix --dry-run --config=.php-cs-fixer.dist.php --using-cache=no --show-progress=none -v"
],
"docker-clean": "docker image rm $(docker image ls -qf reference=pinba-bundle-test)",
"docker": "docker build . -t pinba-bundle-test && docker image prune -f >/dev/null && docker run --rm pinba-bundle-test"
"phpstan": "vendor/bin/phpstan analyse --no-progress"
}
}
Loading
Loading