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

Sniff to limit the use of new? #25

Closed
bmitch opened this issue Dec 4, 2016 · 6 comments
Closed

Sniff to limit the use of new? #25

bmitch opened this issue Dec 4, 2016 · 6 comments

Comments

@bmitch
Copy link
Owner

bmitch commented Dec 4, 2016

Instead of using new should be using DI. Should this be sniffed out?

@bmitch
Copy link
Owner Author

bmitch commented Jul 30, 2017

Maybe leave this as a warning and suggest using DI instead if applicable.

@kevin-schmitt
Copy link
Contributor

Hello,

This issue is always ok? if yes i take please.

Thanks

@kevin-schmitt
Copy link
Contributor

Hello,

Can you help me please ?
I try to register new sniff without success i have message 'sniff no registered'
In my test

<?php declare(strict_types = 1);

namespace Codor\Tests\Sniffs\Classes;

use Codor\Tests\BaseTestCase;

/** @group Classes */
class NewInstanceSniffTest extends BaseTestCase
{

    public function setup()
    {
        parent::setup();

        $this->runner->setSniff('Codor.Classes.NewInstance')->setFolder(__DIR__.'/Assets/NewInstanceSniff/');
    }

    /** @test */
    public function a_constructor_have_warning_if_use_new_class_in_constructor()
    {
        $results = $this->runner->sniff('NewInConstructor.inc');
        $this->assertSame(0, $results->getErrorCount());
        $this->assertSame(1, $results->getWarningCount());

    }
}

I created the sniff
image

When i run the test
image

Thanks

@villfa
Copy link
Collaborator

villfa commented Jan 20, 2022

I see there is a typo in the class name of the Sniff: Intsance instead of Instance.
Not sure if it will fix your issue though.

@kevin-schmitt
Copy link
Contributor

Hello :)

You can close this issue please ?

@villfa
Copy link
Collaborator

villfa commented Aug 12, 2022

Closing since it's done in #153.
Thanks @kevin-schmitt

@villfa villfa closed this as completed Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants