Skip to content

Commit

Permalink
small optimizations (#20)
Browse files Browse the repository at this point in the history
* small optimizations

* minor fixes
  • Loading branch information
nick-zh authored Dec 8, 2021
1 parent fe1f0d1 commit 0d6e73b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docker/docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '3.2'
services:
php:
build:
context: ./
dockerfile: dev/php/Dockerfile
context: docker/dev
dockerfile: php/Dockerfile
args:
HOST_USER: ${USER}
HOST_USER_ID: ${USER_ID}
volumes:
- ../:/var/www/html
- ./:/var/www/html
1 change: 0 additions & 1 deletion docker/.env

This file was deleted.

2 changes: 1 addition & 1 deletion docker/dev/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM php:7.4-cli-alpine3.15
ARG HOST_USER_ID
ARG HOST_USER

COPY dev/php/files/bin/ /usr/local/bin/
COPY php/files/bin/ /usr/local/bin/

# SYS: Install required packages
RUN apk --no-cache upgrade && \
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ parameters:
- "#Call to function token_get_all\\(\\) on a separate line has no effect.#"
- "#Strict comparison using === between array<int, mixed>&nonEmpty and ',' will always evaluate to false.#"
- "#Strict comparison using === between array<int, mixed>&nonEmpty and ';' will always evaluate to false.#"
- "#Method PhpKafka\\\\\\PhpAvroSchemaGenerator\\\\\\Optimizer\\\\\\OptimizerInterface::optimize\\(\\) invoked with 2 parameters, 1 required.#"
15 changes: 7 additions & 8 deletions src/Merger/SchemaMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace PhpKafka\PhpAvroSchemaGenerator\Merger;

use AvroSchema;
use AvroSchemaParseException;
use PhpKafka\PhpAvroSchemaGenerator\Avro\Avro;
use PhpKafka\PhpAvroSchemaGenerator\Exception\SchemaMergerException;
use PhpKafka\PhpAvroSchemaGenerator\Optimizer\OptimizerInterface;
use PhpKafka\PhpAvroSchemaGenerator\Optimizer\PrimitiveSchemaOptimizer;
use PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistryInterface;
use PhpKafka\PhpAvroSchemaGenerator\Schema\SchemaTemplateInterface;

Expand Down Expand Up @@ -65,7 +65,7 @@ public function getResolvedSchemaTemplate(SchemaTemplateInterface $rootSchemaTem
$exceptionThrown = false;

try {
\AvroSchema::parse($rootDefinition);
AvroSchema::parse($rootDefinition);
} catch (AvroSchemaParseException $e) {
if (false === strpos($e->getMessage(), ' is not a schema we know about.')) {
throw $e;
Expand Down Expand Up @@ -124,14 +124,13 @@ public function merge(
foreach ($registry->getRootSchemas() as $rootSchemaTemplate) {
try {
$resolvedTemplate = $this->getResolvedSchemaTemplate($rootSchemaTemplate);

foreach ($this->optimizers as $optimizer) {
$resolvedTemplate = $resolvedTemplate->withSchemaDefinition(
$optimizer instanceof PrimitiveSchemaOptimizer ?
$optimizer->optimize(
$resolvedTemplate->getSchemaDefinition(),
$resolvedTemplate->isPrimitive()
) :
$optimizer->optimize($resolvedTemplate->getSchemaDefinition())
$optimizer->optimize(
$resolvedTemplate->getSchemaDefinition(),
$resolvedTemplate->isPrimitive()
)
);
}
} catch (SchemaMergerException $e) {
Expand Down
4 changes: 4 additions & 0 deletions src/Optimizer/OptimizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@

interface OptimizerInterface
{
/**
* @param string $definition
* @return string
*/
public function optimize(string $definition): string;
}
1 change: 1 addition & 0 deletions src/Optimizer/PrimitiveSchemaOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class PrimitiveSchemaOptimizer extends AbstractOptimizer implements OptimizerInt
{
/**
* @param string $definition
* @param bool $isPrimitive
* @return string
* @throws \JsonException
*/
Expand Down

0 comments on commit 0d6e73b

Please sign in to comment.