npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

phpstan-error-parser

v0.1.0

Published

This parses PHPStan error message into a structured format.

Downloads

3

Readme

phpstan-error-parser

A JavaScript/TypeScript parser that converts PHPStan error messages into a structured format for easier programmatic processing and analysis.

Overview

This is a JavaScript/TypeScript library that parses PHPStan error messages and extracts key components like function names, method names, variables, and doc tags into a structured data format. It uses Chevrotain for lexical analysis and parsing.

Features

  • Parse PHPStan error messages into structured tokens
  • Extract and identify:
    • Function names (including namespaced functions)
    • Method names (both static and instance methods)
    • Variable names
    • PHPDoc tags
    • Common words
  • Get location information (start/end columns) for each token
  • Built with TypeScript for type safety

Tasks

  • [x] comma

  • [ ] -> ("Using nullsafe method call on non-nullable type Exception. Use -> instead.")

  • [ ] number as a word (-123, 8.5)

  • [ ] number as a type (array{1, 3})

  • [ ] error including parameter number(#1, #2, ...)

  • [ ] static keyword(static::)

  • [ ] types

    • [ ] array types (int[], string[][])
    • [ ] array shapes (array{key: value, ...}, array{0}, array{})
    • [ ] generic types (Path\SomeClass<int, string>, array<int, string>)
    • [ ] Union type
    • [ ] Intersection type
  • [] more...

Installation

npm install phpstan-error-parser

Usage

import { parse } from 'phpstan-error-parser';

const errorMessage = "Function format not found.";
const words = parse(errorMessage);

console.log(words);
// Output:
// [
//   { type: 'common_word', value: 'Function', location: { startColumn: 0, endColumn: 8 } },
//   { type: 'function_name', value: 'format', location: { startColumn: 9, endColumn: 15 } },
//   { type: 'common_word', value: 'not', location: { startColumn: 16, endColumn: 19 } },
//   { type: 'common_word', value: 'found', location: { startColumn: 20, endColumn: 25 } },
//   { type: 'period', value: '.', location: { startColumn: 25, endColumn: 26 } }
// ]

API

parse(errorMessage: string): Word[]

Parses a PHPStan error message and returns an array of structured word tokens.

Parameters:

  • errorMessage: The PHPStan error message string to parse

Returns:

  • An array of Word objects

Word Type

type Word = {
  type: "function_name" | "method_name" | "variable_name" | "doc_tag" | "common_word" | "period";
  value: string;
  location: {
    startColumn: number;
    endColumn: number;
  };
};

Supported Patterns

The parser can identify:

  • Function names: Function format, Function abc\format (with namespaces)
  • Method names: Method formatString(), method getData
  • Variables: $variable, $user_name
  • Doc tags: @param, @return, @var
  • Common words: Regular words in the error message
  • Punctuation: Periods marking sentence endings

Development

Setup

git clone <repository-url>
cd phpstan-error-parser
npm install

Running Tests

npm test

Development Server

View the parser diagram visualization like Chevrotain Playground:

npm run diagram

Offset Calculator CLI

A development tool to calculate word offsets for testing purposes:

# Link the package globally (run once)
npm link
# Use the CLI from anywhere
calc-offset "Function format not found."

|0       |9      |16  |20
Function format  not  found.
       |8     |15  |19     |26
# Unlink when done
npm unlink -g phpstan-error-parser

Project Structure

├── src/
│   ├── parser.ts    # Lexer and parser definitions
│   ├── format.ts    # CST to structured format converter
│   └── index.ts     # Main export
├── test/
│   ├── parser.spec.ts
│   └── format.spec.ts
└── package.json

Examples

Parsing a Method Error

const errorMessage = "Method formatString() not found in class MyClass.";
const words = parse(errorMessage);
// Extracts 'formatString()' as a method_name token

Parsing with Variables

const errorMessage = "Variable $userName is not defined.";
const words = parse(errorMessage);
// Extracts '$userName' as a variable_name token

Parsing with Doc Tags

const errorMessage = "Invalid @param tag in docblock.";
const words = parse(errorMessage);
// Extracts '@param' as a doc_tag token

License

MIT

Credit

Keywords

  • PHPStan
  • parser
  • static analysis
  • error parsing