Download the PHP package alisqi/twigqi without Composer

On this page you can find all versions of the php package alisqi/twigqi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twigqi

TwigQI: Static code analysis for Twig templates

License PHP Version Stability Build Status codecov

Twig Quality Inspections is an extension to the Twig templating engine which adds static analysis (i.e., compile-time) inspections and runtime assertions to increase templates' quality. See the inspections section below for details.

Unlike other projects like curlylint and djLint, which focus on HTML, this tool exclusively analyzes the Twig code.

The two intended use cases are:

[!NOTE] TwigQI is stable and should work in most codebases due to its simplicity. I would love to hear about your experience using it. Please create an issue or a pull request if you've found an issue. 🙏

Note that TwigQI doesn't support every single edge case, plus it is a little opinionated. You've been warned! 😉 The good news is that you can easily create a bespoke suite by cherry-picking the inspections.

Justification

Just in case you need convincing, please consider the following example:

Here, usr.admin is obviously a typo. Fortunately, this bug is easily detected with strict_types enabled, but only if the macro is called with showBadge=true, which might be uncommon enough to go unnoticed during development. In this example, the (admin) badge will simply never be printed in production, where strict_types is likely disabled. A bug for sure, but perhaps not a critical one.

However, user.getRoleLabel(usr.role) will cause an uncaught TypeError if that method's parameter is not nullable, since Twig will call that method with null. Instead of just having a buggy badge, the whole page breaks.

Usage

First, install using

Next, add the extension to your Twig\Environment:

Any issues will be reported using PHP's trigger_error with E_USER_* levels. Set up your app and/or CI build to report these as you see fit.

And that's it! 😎

Design

The current design uses NodeVisitor classes for every inspection. That allows for easy testing and configurability.

The reason the inspections use trigger_error instead of Exceptions is that the latter would halt compilation, preventing the extension from reporting multiple issues in one go.

The level of error (error, warning, notice) depends entirely on the authors' opinions on code quality. E_USER_ERROR is used for, well, errors, that the author(s) deem actual errors in code. For more opinionated issues (e.g., relying on macro arguments always being optional), E_USER_WARNING is used.

Typing system and syntax

Many inspections rely on proper typing. However, the documentation for the types tag explicitly avoids specifying the syntax or contents of types.

So how should developers declare types? While PHP developers are often familiar with PHPStan, Twig template designers may instead be used to TypeScript.

The Twig documentation sums up its stance succinctly:

Twig tries to abstract PHP types as much as possible and works with a few basic types[.]

Therefore, TwigQI uses the basic types described by Twig, while defining syntax for iterables. The goal is to have a simple type system that's easy to learn and use, and which should cover the vast majority of use cases.

Your preferences and/or requirements may very well differ.

Here's the list of types supported by TwigQI:

Any type can be prefixed with ? to make it nullable.

Note that there's no dedicated syntax for iterables with particular, known keys. Nor can you declare that values have different types. You could use one of the iterable variants (e.g., iterable<string, mixed>), but I would humbly recommend using a readonly class to act as a view model.

Inspections

Here's the list of inspections already considered relevant and feasible.

Those marked with ⌛ are planned / considered, while ✅ means the inspection is implemented.

Note that most of these could also be analyzed by PHPStan if it could properly understand (compiled) templates and how they are rendered. This is the aim of a similar project: TwigStan.

Typed variables

Constants

Macros

While Twig considers all macro arguments optional (and provides null as a default), TwigQI considers arguments with no explicit default value as required.

Acknowledgments

Big thanks to Ruud Kamphuis for TwigStan, and for helping on this very project.


All versions of twigqi with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
twig/twig Version ^3.13
phpdocumentor/reflection-docblock Version ^5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alisqi/twigqi contains the following files

Loading the files please wait ....