PHPackages                             dbstudios/analyst - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dbstudios/analyst

ActiveLibrary

dbstudios/analyst
=================

A feature testing library inspired by GitHub's Scientist

2.0.1(10y ago)1217MITPHPPHP &gt;= 5.6

Since Jan 26Pushed 10y ago2 watchersCompare

[ Source](https://github.com/LartTyler/Analyst)[ Packagist](https://packagist.org/packages/dbstudios/analyst)[ RSS](/packages/dbstudios-analyst/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/0c93e57218c66f65326201e69da736bd0e52abca8724eab8be063914144223ff/68747470733a2f2f7472617669732d63692e6f72672f4c61727454796c65722f416e616c7973742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/LartTyler/Analyst)[![Coverage Status](https://camo.githubusercontent.com/ada89a2c9f0328952b36fdf2665941812d15ba9037650fd3114f1116a4161111/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4c61727454796c65722f416e616c7973742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/LartTyler/Analyst?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/297302d251d671d6dcf375766036db68a9ff75ba49dc0fb40d28ccd51f6d5bf6/68747470733a2f2f706f7365722e707567782e6f72672f646273747564696f732f616e616c7973742f762f737461626c65)](https://packagist.org/packages/dbstudios/analyst)[![Total Downloads](https://camo.githubusercontent.com/ff628be91c3c9d08e08aa691544a24011432e3b1e33196d67c8be5201e7eeba2/68747470733a2f2f706f7365722e707567782e6f72672f646273747564696f732f616e616c7973742f646f776e6c6f616473)](https://packagist.org/packages/dbstudios/analyst)[![License](https://camo.githubusercontent.com/dc94811ecc4b942e63728b52d85a10cb0271f0b3caa88f0662603bb2c7713465/68747470733a2f2f706f7365722e707567782e6f72672f646273747564696f732f616e616c7973742f6c6963656e7365)](https://packagist.org/packages/dbstudios/analyst)

Analyst
=======

[](#analyst)

A PHP feature testing library inspired by GitHub's Scientist.

Please be aware, this README is a work in progress, and may contain incomplete information.

Installation
============

[](#installation)

```
$ composer require dbstudios/analyst
```

How do I analyze?
=================

[](#how-do-i-analyze)

Let's pretend that you have a large web application, and are in the process of changing the way you verify user permissions when accessing a page.

```
class MyController {
    public function isAllowed(User $user, $slug) {
        return Experiment::create('user-allowed')
            ->setContext([
                'user' => $user, // context ignores keys, however it's helpful to use keys to "flag" what each variable means
                'slug' => $slug,
            ])
            ->control(function(User $user, $slug) {
                return $user->isAdmin() || $user->getPermissions()->contains('view.page.' . $slug);
            })
            ->candidate(function(User $user, $slug) {
                return $user->getPermissionProvider()->isAccessAllowed($slug);
            })
            ->run();
    }
}
```

That's it! The `run` method of `Experiment` will always return the result from your control. Both your control and your candidate will be run, and Analyst will record what happened to both blocks of code. In the next section, we'll take a look at what you can do with that information.

Publishing Experiment Results
=============================

[](#publishing-experiment-results)

Testing multiple code paths is pretty useless if we don't do anything with the information we get from our experiment. That's where publishing comes into play. All you need to do is implement that `publish` method in a custom `Experiment`class.

```
class MyExperiment extends Experiment {
    private $db;
    private $stmt;

    public function __construct(PDO $db, $name = 'experiment') {
        parent::__construct($name);

        $this->db = $db;
        $this->stmt = $db->prepare('insert into experiment_results (name, timestamp, behavior, is_control,
            execution_time, result) values(:experiment, UTC_TIMESTAMP(), :behavior, :control, :duration, :result)');

        $this->stmt->bindValue(':experiment', $name);
    }

    public function publish(Result $result) {
        $behaviors = $result->getCandidates();

        array_unshift($candidates, $result->getControl());

        $this->db->beginTransaction();

        foreach ($behaviors as $behavior) {
            $this->stmt->bindValue(':behavior', $behavior->getName());
            $this->stmt->bindValue(':control', $behavior === $result->getControl(), PDO::PARAM_BOOL);
            $this->stmt->bindValue(':duration', $behavior->getDuration());
            $this->stmt->bindValue(':result', serialize($behavior->getResult());

            $this->stmt->execute();
        }

        $this->db->commit();
    }

    public static function create($db, $name = 'experiment') {
        return new MyExperiment($db, $name);
    }
}
```

Now, if we were to rewrite our earlier user permission example to use our custom `MyExperiment` class, it would look like this.

```
class MyController {
    public function isAllowed(User $user, $slug) {
        return MyExperiment::create($this->getConnection(), 'user-allowed')
            // set up context, control, and candidate...
            ->run();
    }
}
```

In the above example, we created our own `Experiment` implementation, named `MyExperiment`. In it, we made sure we had a database connection (using PHP's `PDO` class), and wrote data to it using the `publish` method. Then, when we ran our experiment within our controller example, all we needed to do was provide the extra arguments to the `create` static method of `MyExperiment` (which we implemented ourselves to allow for the additional constructor argument).

After every experiment is run, Analyst will always call the `publish` method of the experiment used to do our analysis. Our options aren't limited to simple database inserts. You might decide to log the data to a file using a library like Monolog, or you might send it off to a cloud service. It's up to you!

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

3758d ago

Major Versions

1.0.0 → 2.0.02016-01-27

PHP version history (2 changes)1.0.0PHP &gt;= 5.4

2.0.0PHP &gt;= 5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/770791?v=4)[Tyler Lartonoix](/maintainers/LartTyler)[@LartTyler](https://github.com/LartTyler)

---

Top Contributors

[![LartTyler](https://avatars.githubusercontent.com/u/770791?v=4)](https://github.com/LartTyler "LartTyler (36 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dbstudios-analyst/health.svg)

```
[![Health](https://phpackages.com/badges/dbstudios-analyst/health.svg)](https://phpackages.com/packages/dbstudios-analyst)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
