Skip to content

Extractor does not extract enum method body using EnumType::from() and withBodies: true #115

@sisklu

Description

@sisklu

Version: 4.0.3

Bug Description

When using EnumType::from with argument withBodies set to true, the extracted enum method has no body.

Steps To Reproduce

<?php

require_once __DIR__ . "/vendor/autoload.php";

enum Color
{
	case Red;
	case Blue;
	case Green;

	public function getColor(): string
	{
		return $this->name;
	}
}

echo \Nette\PhpGenerator\EnumType::from('Color', withBodies: true);

gives

enum Color
{
	case Red;
	case Blue;
	case Green;

	public function getColor(): string
	{
	}
}

Expected Behavior

enum Color
{
	case Red;
	case Blue;
	case Green;

	public function getColor(): string
	{
		return $this->name;
	}
}

Possible Solution

Condition here in Extractor

fn(Node $node) => ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_)

should also check if node is instance of Node\Stmt\Enum_.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions