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

Laravel 8 Issue: Too few arguments to function Spatie\Enum\Enum #70

Closed
SuperlativeEntity opened this issue Sep 30, 2020 · 6 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@SuperlativeEntity
Copy link

SuperlativeEntity commented Sep 30, 2020

I'm getting the following error:

In Enum.php line 53

Too few arguments to function Spatie\Enum\Enum::__construct(), 0 passed in app\Enums\BankAccountTypeEnum.php on line 11 and exactly 1 expected

app\Enums\BankAccountTypeEnum.php


namespace App\Enums;

use Spatie\Enum\Enum;

abstract class BankAccountTypeEnum extends Enum
{
    public static function current(): BankAccountTypeEnum
    {
        return new class() extends BankAccountTypeEnum
        {
            public function getIndex(): int
            {
                return 1;
            }

            public function getValue(): string
            {
                return 'Current / Cheque';
            }
        };
    }

    public static function savings(): BankAccountTypeEnum
    {
        return new class() extends BankAccountTypeEnum
        {
            public function getIndex(): int
            {
                return 2;
            }

            public function getValue(): string
            {
                return 'Savings';
            }
        };
    }

    public static function transmission(): BankAccountTypeEnum
    {
        return new class() extends BankAccountTypeEnum
        {
            public function getIndex(): int
            {
                return 3;
            }

            public function getValue(): string
            {
                return 'Transmission';
            }
        };
    }
}

config\custom\cdv.php

<?php

use App\Enums\BankAccountTypeEnum;

// config('custom.cdv.enabled')
return
[
    'enabled'       => env('CDV_ENABLED',false), // config('custom.cdv.enabled')
    'api'           => env('CDV_API'), // config('custom.cdv.api')
    'endpoint'      => env('CDV_ENDPOINT'), // config('custom.cdv.endpoint')
    'username'      => env('CDV_USERNAME'), // config('custom.cdv.username')
    'password'      => env('CDV_PASSWORD'), // config('custom.cdv.password')

    'curl_options'  => // config('custom.cdv.curl_options')
    [
        CURLOPT_CONNECTTIMEOUT  => 10,
        CURLOPT_TIMEOUT         => 30,
        CURLOPT_SSL_VERIFYHOST  => 2
    ],

    'test_account'  =>
    [
        'bank_bank'             => '',
        'bank_branch'           => '',
        'bank_branch_code'      => '',
        'bank_number'           => '',
        'bank_account_type'     => 'savings'
    ],
    
    // snapbill mapping
    'account_types'  => // config('custom.cdv.account_types')
    [
        BankAccountTypeEnum::current()->getIndex()       => 'current',
        BankAccountTypeEnum::savings()->getIndex()       => 'savings',
        BankAccountTypeEnum::transmission()->getIndex()  => 'transmission'
    ],
];
@SuperlativeEntity
Copy link
Author

Seem like version 3 is completely different and is not backward compatible

@xewl
Copy link
Contributor

xewl commented Sep 30, 2020

Just got the same issue in the laravel-enum package (... and the :nullable cast gets validated as __construct("nullable") )
I'm guessing it's too strict in always wanting a value on the constructor.

I'll have to revert my changes. :(

@Gummibeer
Copy link
Collaborator

Hey,

if the BankAccountTypeEnum code is the one you try to run with v3 the issue is the usage of the static methods which return a new instance of the enum.
The v3 has completely dropped the support of static methods in favor of doc-tags and the new values() and labels() methods.
And your methods don't do anything that wouldn't be possible with the v3 way.

@Gummibeer Gummibeer self-assigned this Sep 30, 2020
@Gummibeer Gummibeer added the question Further information is requested label Sep 30, 2020
@SuperlativeEntity
Copy link
Author

I will just convert all of my enums to the new way

@ryanrapini
Copy link

Sorry to bump this old thread, but since it was the first result for me when googling: if you're seeing this error in your Laravel project, it's also possible you're dumb like me and you mixed up spatie/laravel-enum and spatie/enum.

@xewl
Copy link
Contributor

xewl commented Jun 1, 2021

Sorry to bump this old thread, but since it was the first result for me when googling: if you're seeing this error in your Laravel project, it's also possible you're dumb like me and you mixed up spatie/laravel-enum and spatie/enum.

At that time, as directed towards in spatie/laravel-enum#53 it was indeed a bit unclear that v3 had a new Base class especially made for Laravel.
Docs were fixed by @Gummibeer & the solution is fixing the namespace of the import to that new Base class.
See spatie/laravel-enum's README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants