Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Get rid of more arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Jul 10, 2024
1 parent fc43816 commit b8b5037
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
9 changes: 9 additions & 0 deletions lib/class-argument-datalist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WP_Parser;

final readonly class ArgumentDataList extends DTOList {
public function __construct( ArgumentData ...$data ) {
parent::__construct( ...$data );
}
}
9 changes: 9 additions & 0 deletions lib/class-hook-datalist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WP_Parser;

final readonly class HookDataList extends DTOList {
public function __construct( HookData ...$data ) {
parent::__construct( ...$data );
}
}
2 changes: 1 addition & 1 deletion lib/class-method-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
public bool $abstract,
public bool $static,
public string $visibility,
public array $arguments,
public ArgumentDataList $arguments,
public DocBlockData $doc,
) {}
}
9 changes: 9 additions & 0 deletions lib/class-method-datalist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WP_Parser;

final readonly class MethodDataList extends DTOList {
public function __construct( MethodData ...$data ) {
parent::__construct( ...$data );
}
}
9 changes: 9 additions & 0 deletions lib/class-property-datalist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WP_Parser;

final readonly class PropertyDataList extends DTOList {
public function __construct( PropertyData ...$data ) {
parent::__construct( ...$data );
}
}
25 changes: 8 additions & 17 deletions lib/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ function export_docblock( Property|Method|Hook|File|Function_|Class_ $element )

/**
* @param \phpDocumentor\Reflection\Php\Argument[] $arguments
*
* @return array<int, ArgumentData>
*/
function export_arguments( array $arguments ) : array {
function export_arguments( array $arguments ) : ArgumentDataList {
$output = array();

foreach ( $arguments as $argument ) {
Expand All @@ -158,15 +156,13 @@ function export_arguments( array $arguments ) : array {
);
}

return $output;
return new ArgumentDataList( ...$output );
}

/**
* @param \phpDocumentor\Reflection\Php\Property[] $properties
*
* @return array<int, PropertyData>
*/
function export_properties( array $properties ) : array {
function export_properties( array $properties ) : PropertyDataList {
$out = array();

foreach ( $properties as $property ) {
Expand All @@ -181,19 +177,16 @@ function export_properties( array $properties ) : array {
);
}

return $out;
return new PropertyDataList( ...$out );
}

/**
* @param \phpDocumentor\Reflection\Php\Method[] $methods
*
* @return array<int, MethodData>
*/
function export_methods( array $methods ) : array {
function export_methods( array $methods ) : MethodDataList {
$output = array();

foreach ( $methods as $method ) {

$namespace = get_namespace( $method->getFqsen() );

$output[] = new MethodData(
Expand All @@ -210,15 +203,13 @@ function export_methods( array $methods ) : array {
);
}

return $output;
return new MethodDataList( ...$output );
}

/**
* @param HooksMetadata $hooks_metadata
*
* @return array<int, HookData>
*/
function export_hooks( HooksMetadata $hooks_metadata ) : array {
function export_hooks( HooksMetadata $hooks_metadata ) : HookDataList {
$out = array();

/** @var Hook $hook */
Expand All @@ -233,7 +224,7 @@ function export_hooks( HooksMetadata $hooks_metadata ) : array {
);
}

return $out;
return new HookDataList( ...$out );
}

/**
Expand Down

0 comments on commit b8b5037

Please sign in to comment.