Coder Social home page Coder Social logo

wrk-flow / larastrict Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 4.81 MB

Opinionated extension of a Laravel framework to help you build type safe, testable and reusable code.

Home Page: https://larastrict.com

License: MIT License

PHP 99.99% Blade 0.01%
laravel php php81 strict-types

larastrict's People

Contributors

h4kuna avatar pionl avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

larastrict's Issues

PHPStan rules

  • Queries folder name convention and "Query" suffix
  • Caches folder name convention and "Cache" suffix
  • Services folder name convention and "Service" suffix
  • Entities folder name convention and "Entity" suffix
  • Actions folder name convention and "Action" suffix

Commands: Extract interface, update service provider binding, generate assert

Now we have to manually:

  • extract implementation to interface (Contract) in Contracts namespace
  • (PHPStorm does) replace usage of the implementation and use interface
  • update service provider $bindings and adding Contract => implementation binding
  • generate assert expectations php artisan make:expectation {path}

Use combination of rector + Laravel command?

Command: Testing expectation - support closures

If we are using closures, we can generate from closure typehints expected result and input parameters:

expectation would not create Closure $createData but

public readonly NotebookPageEntity $createDataPage,
        public readonly NotebookFinancePageEntity $createDataResultResult,
Assert::assertEquals($createData($expectation->createDataResultPage), $expectation->createDataResult, $message);

CacheMe namespace support

  • when injecting cacheme service we
  • maybe we can use attribute (class attribute)
  • when building class DI, we can return prefixed cachme service with namespace set to all keys.

CacheMe - cache entity

When using get/set methods, it would be great to wrap cacheMeService in entity/class that would pass $key and strategy.

This would prevent bugs when using set with incorrect strategy

Proposals:

/** @var CacheEntity<string> $cache */
$cache = new CacheEntity(key: $key, strategy: CacheMeStrategy::Memory);
                
$value = $cache->get($this->cacheMeService);
$cache->set($this->cacheMeService, $value);
/** @var CacheEntity<string> $cache */
$cache = new CacheEntity(service: $this->cacheMeService, key: $key, strategy: CacheMeStrategy::Memory);
// construct with service
$cache = $this->cacheMeService->cache($key, strategy: CacheMeStrategy::Memory)
                
$value = $cache->get();
$cache->set($value);

@h4kuna what do you prefer?

PHPStan: check whereBetween

When using where between with a datetime column there can be a bug. We should try to detect it.

  • If we are using Model::CREATED_AT / Model::UPDATED_AT / MODEL::DELETED_AT
  • If we are using Model::AtttributeX we could check the $casts?
  • if we are using a string 'created_at', 'deleted_at', 'updated_at', maybe '%_at' ?

ChunkedModelQueryResult: Introduce TEntry template

  • TModel @template will be used for setTransformOnEntry
  • TEntry @template will be used for onEntry/onChunk

This will be breaking change in PHPStan reports.

Syntax will be:

ChunkedModelQueryResult<MyModel,MyEntity>
ChunkedModelQueryResult<MyModel,MyModel >

SoftDeletes interface

  • add soft deletes interface so we can detect soft deletes logic in type safe way
  • rector/phpstan - Add interface if class that uses SoftDeletes trait does not use the interface

make:expectation command for stricter testing

  • Generate expectation
  • Add ExpectationCallMap
  • Generate assert mock
  • Add support for return
  • Add name of asserted attribute name
  • Add ability to re-generate all asserts/expectations?
  • Asset for assert class to check if the method for called expect number of times?

Example of a mock:

/**
 * @extends ExpectationCallMap<GetTourIdForObjectTypeBoardQueryContractExpectation>
 */
class GetTourIdForObjectTypeBoardTestQuery extends ExpectationCallMap implements GetTourIdForObjectTypeBoardQueryContract
{
    public function execute(int $objectId, int $objectTypeId, int $boardId): ?int
    {
        $expectation = $this->getExpectation();

        Assert::assertEquals($expectation->objectId, $objectId);
        Assert::assertEquals($expectation->objectTypeId, $objectTypeId);
        Assert::assertEquals($expectation->boardId, $boardId);
    }
}

Commands and log

Problem

When using commands we have actions / services that logs different states. It would be great to prevent logging this to a log file (when using docker all logs are visible to user using stderr) when using command (called by user, not in schedule) and output it directly to user

Problem is detecting if the command was called via artisan.

Current state

At this moment there is partially working solution.

Proposal

  • This can be done by replacing LogInterface with console output (currently we have this)
  • Also it would be great to make the output nicer (like trying to group same stuff with "similar" context)

Advanced cache system

  • automatic event listeners (via boot)
  • cache to memory (and optionally to cache layer)

PHPStan: check if view can be resolved

From larastran rule:

  • view helper function.
  • $this->markdown and $this->view methods in Mailables.
  • Illuminate\View\Factory::make method.
  • Illuminate\Support\Facades\View::make method.
  • Illuminate\Support\Facades\Route::view method.

ChunkedModelQueryResult - support

/**
 * @template TModel of \Illuminate\Database\Eloquent\Model
 * @template TEntry
 */
  • Change the closure(TModel) to closure(Entry)
  • will be breaking change for phpstan (thats OK)
  • add "test" file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.