• This repository has been archived on 23/Apr/2024
  • Stars
    star
    159
  • Rank 228,767 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Validate the architecture of your PHP project based on the concept of function colors

image

Go Report Card GitHub license

NoColor — validate the architecture of your PHP project

NoColor is an architecture validation tool based on the concept of colored functions. This concept was originally invented for KPHP and later exposed as a separate tool to be used in regular PHP projects.

NoColor and Deptrac have similar goals: they both search for bad architectural patterns. But NoColor uses an absolutely different scenario: function coloring. Unlike Deptrac, NoColor analyzes call chains of any depth and supports type inferring. Continue reading NoColor vs Deptrac.

NoColor performs static code analysis, it has no runtime overhead. It supports type inferring to handle instance method calls, but dynamic invocations like A::$method() can't be statically analyzed.

NoColor is built on top of NoVerify and written in Go.

Optionally, install an experimental plugin for PhpStorm that brings some handy features.

Theoretically, the same concept can be implemented for almost every language. NoColor targets PHP.

A brief intro to colors

Using the @color PHPDoc tag, you assign colors to a function. When a function calls another one, their colors combine to a chain:

/** @color green */
function f1() { f2(); }

// this function has no color (it's transparent)
function f2() { f3(); }

/** @color red */
function f3() { /* ... */ }

f1 f2 f3 colored

In the palette, you define rules of colors mixing, as this error rule:

green red: calling red from green is prohibited

All possible call chains are pattern-matched against rules. Hence, f1 -> f2 -> f3 will trigger the error above.

A color is anything you want: @color api, or @color model, or @color controller. With the palette, you define arbitrary patterns and exceptions. You can mark classes and use namespaces. You can express modularity and even simulate the internal keyword.

Continue reading about colors here

Getting started

The Getting started page contains a step-by-step guide and copy-paste examples.

The palette.yaml file

Once you call

nocolor init

at the root of your project, it creates an example palette.yaml file. It contains rules of color mixtures:

first group title:
- rule1 color pattern: rule1 error or nothing
- rule2 color pattern: rule2 error or nothing
# other rules in this group

# optionally, there may be many groups

Consider the Configuration page section.

Running NoColor

At first, install NoColor to your system. The easiest way is just to download a ready binary.

Then, execute this command once at the root of your project:

nocolor init

It will create a palette.yaml file with some examples.

Every time you need to check a project, run

nocolor check

to perform checking in the current directory, or

nocolor check ./src

to perform checks in another folder (or many).

To exclude some paths from analyzing, or to include the ./vendor dir, consider all possible command-line options.

Limitations and speed

As for now, NoColor supports PHP 7.4 language level. It depends on a Go package php-parser which is currently frozen. This restriction can be overcome in the future.

NoColor scales easily to the capacities provided. Depending on the number of cores and the speed of a hard disk, NoColor can process up to 300k lines per second.

The number of groups, colors, and selectors is unlimited, though the more functions are colored — the slower NoColor would work, as the number of colored graph paths exponentially increases. Typically, 99% of classes/functions are supposed to be left transparent.

All available call chains are calculated on a static analysis phase, there is no runtime overhead. NoColor uses some tricky internal optimizations to avoid useless depth searching in a call graph. Every possible colored call chain is matched against all rules in the palette.

Remember, that PHP is an interpreted language and allows constructions that can't be statically analyzed. If you write something like SomeClass::$any_function() or new $class_name, NoColor can't do anything about it.

Contributing

Feel free to contribute to this project. See CONTRIBUTING.md for more information.

The License

NoColor is distributed under the MIT License, on behalf of VK.com (V Kontakte LLC).

More Repositories

1

kphp

KPHP — a PHP compiler
C++
1,294
star
2

VKUI

VKUI – это набор React-компонентов, с помощью которых можно создавать интерфейсы, внешне неотличимые от наших iOS и Android приложений.
TypeScript
964
star
3

YouTokenToMe

Unsupervised text tokenizer focused on computational efficiency
C++
944
star
4

noverify

Pretty fast linter (code static analysis utility) for PHP
Go
657
star
5

vk-android-sdk

Android library for working with VK API, authorization through VK app, using VK functions.
Kotlin
454
star
6

vk-ios-sdk

iOS library for working with VK API, authorization through VK app, using VK functions
Objective-C
295
star
7

vk-java-sdk

Java library for working with VK API
Java
289
star
8

vk-api-schema

JSON Schema of VK API
Shell
205
star
9

vk-php-sdk

PHP library for working with VK API
PHP
200
star
10

statshouse

StatsHouse is a highly available, scalable, multitenant monitoring system
Go
190
star
11

kittenhouse

Go
184
star
12

lighthouse

Lightweight interface for ClickHouse
JavaScript
182
star
13

joy4

Golang audio/video library and streaming server
Go
179
star
14

vkompose

Kotlin Compiler Plugins, an IDEA Plugin, and a Detekt Rule that will help to improve your experience with Jetpack Compose
Kotlin
154
star
15

nginx-quic

C
150
star
16

KNet

Android network library with QUIC protocol supporting.
Kotlin
144
star
17

nocc

A distributed C++ compiler: like distcc, but faster
Go
133
star
18

bot-example-php

Пример бота для VK
PHP
131
star
19

icons

Набор SVG иконок, представленный в виде React компонентов.
JavaScript
122
star
20

vk-bridge

A package for integrating VK Mini Apps with official VK clients for iOS, Android and Web
TypeScript
69
star
21

php-parser

PHP parser written in Go
Go
69
star
22

modulite

A plugin for PHPStorm that brings modules to the PHP language
Kotlin
63
star
23

vk-qr

VK QR Code generator library
TypeScript
57
star
24

create-vk-mini-app

Create VK Apps with no build configuration.
TypeScript
51
star
25

vk-miniapps-deploy

NPM module for deploy VK Mini Apps on VK hosting
JavaScript
49
star
26

kphpstorm

A PhpStorm plugin that makes IDE understand KPHP specifics
Kotlin
41
star
27

fastXDM

fast library for cross-domain messaging
JavaScript
38
star
28

vkui-tokens

TypeScript
37
star
29

node-vk-call

Simple API wrapper for VK.com social network
JavaScript
35
star
30

vk-streaming-api

Go
33
star
31

elephize

Typescript to PHP translation tool
TypeScript
31
star
32

vk-mini-apps-api

The official package for quick and easy development of VK Mini Apps
TypeScript
29
star
33

vk-mini-apps-router

TypeScript
27
star
34

Appearance

JavaScript
26
star
35

devicehub

JavaScript
26
star
36

vk-router

TypeScript
23
star
37

vkid-android-sdk

Kotlin
22
star
38

vk-windowsphone-sdk

VK SDK for Windows Phone
C#
22
star
39

vkjs

VK shared JS libs
TypeScript
21
star
40

vk-unity-sdk

C#
20
star
41

vk-tunnel-client

TypeScript
19
star
42

kive

Go
19
star
43

admstorm

PhpStorm plugin aimed at simplifying tasks at the junction of the local repository and the repository on the dev server
Kotlin
19
star
44

vkdata-sketchplugin

Sketch plugin for using data from your account at vk.com
JavaScript
17
star
45

vk-apps-launch-params

Пример работы с параметрами запуска
JavaScript
17
star
46

tl

Go
16
star
47

nginx-http-vkupload-module

C
16
star
48

superappkit-android-demo

Kotlin
15
star
49

IOSDevice

A set of hacks and workarounds for iOS Safari & Co.
JavaScript
14
star
50

kphp-polyfills

PHP implementations of functions supported by KPHP natively (a Composer package)
PHP
14
star
51

modulite-phpstan

Bring modules into PHP and PHPStan
PHP
13
star
52

vk-mini-apps-examples

TypeScript
12
star
53

vk-apps-tensorflow-example

VK apps + tensorflow-js demo app
JavaScript
12
star
54

api-schema-typescript-generator

TypeScript
11
star
55

api-schema-typescript

TypeScript
10
star
56

vkid-web-sdk

TypeScript
10
star
57

vk-bridge-mock

The VK Bridge mock library
TypeScript
10
star
58

Delegate

Python
10
star
59

engine-go

Common libraries for our go engines (microservices)
Go
10
star
60

vk-direct-games-example

JavaScript
10
star
61

vk-ios-urlprotocol-example

This is an example iOS app with custom URLProtocol
Swift
10
star
62

docker-emulator-android

Dockerfile
9
star
63

VKSDK-iOS

Swift
9
star
64

ktest

Test and benchmark KPHP code
Go
9
star
65

swc-plugin-css-modules

Rust
8
star
66

vk-ads-retargeting-demo

Демонстрация JavaScript API ретаргетинга ВКонтакте
HTML
8
star
67

eslint-config

JavaScript
8
star
68

vkid-ios-sdk

Swift
8
star
69

useWeb3

JavaScript
8
star
70

TL-Schema-idea-plugin

Plugin for JetBrains products for coloring TL Schema files
Java
8
star
71

vk-connect-promise

A package for integrating VK Mini Apps with official VK clients for iOS, Android and Web with events based on promises
JavaScript
8
star
72

torch_mobile

Torch7 for mobile devices
C
7
star
73

vkui-benchmarks

JavaScript
7
star
74

noverify-phpstorm

NoVerify plugin for PhpStorm
Kotlin
6
star
75

superappkit-ios

Ruby
6
star
76

VideoPlayer-iOS

Swift
6
star
77

statshouse-go

StatsHouse client library for Go
Go
6
star
78

create-vkui-app

JavaScript
6
star
79

m3u8

Parser and generator of M3U8-playlists for Apple HLS.
Go
5
star
80

swc-plugin-transform-remove-imports

Rust
5
star
81

nginx-statshouse-module

StatsHouse module for nginx
C
5
star
82

statshouse-cpp

StatsHouse client library for C++
C++
5
star
83

statshouse-php

StatsHouse client library for PHP and KPHP
PHP
5
star
84

stylelint-config

TypeScript
4
star
85

modulite-example-project

This example project contains some Modulite errors, detected by IDE, PHPStan, and KPHP
PHP
4
star
86

kphp-tools

A set of independent tools to work with KPHP compiled code
JavaScript
4
star
87

kphp-snippets

Libraries written in PHP aimed to be compiled with KPHP
PHP
4
star
88

graph-cache

Easy way to build and maintain persistent dependency graph for any type of files/languges
JavaScript
4
star
89

sprites

Module for generate SVG sprites and PNG fallback
JavaScript
4
star
90

gulp-portal

JavaScript
4
star
91

statshouse-java

Java
3
star
92

mask-assets

AngelScript
3
star
93

mini-apps-analytics

TypeScript
3
star
94

vk-apps-currency

JavaScript
3
star
95

swc-plugin-pre-paths

Rust
2
star
96

vk-apps-qr

VK Apps + QR demo app
JavaScript
2
star
97

ktest-script

PHP
2
star
98

prettier-config

JavaScript
2
star
99

mvk-mini-apps-scroll-helper

JavaScript
2
star
100

statshouse-py

StatsHouse client library for Python
Python
2
star