PHPackages                             misterspelik/rpn-calculator - 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. [CLI &amp; Console](/categories/cli)
4. /
5. misterspelik/rpn-calculator

ActiveLibrary[CLI &amp; Console](/categories/cli)

misterspelik/rpn-calculator
===========================

RPN Calculator

1(6y ago)03MITPHPPHP &gt;=7.1.0CI failing

Since Jan 30Pushed 6y ago1 watchersCompare

[ Source](https://github.com/misterspelik/rpn-calculator)[ Packagist](https://packagist.org/packages/misterspelik/rpn-calculator)[ RSS](/packages/misterspelik-rpn-calculator/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Reverse Polish Notation Calculator
==================================

[](#reverse-polish-notation-calculator)

This is PHP implementation of RPN Calculator.

Solution description
--------------------

[](#solution-description)

Package consists of several classes and was designed for future usage as Composer package. Concept is having Rpn\\Calculator class which is Singleton designed in order to be the same instance in possibly different parts of Application which uses it. It injects dependencies such as:

- work with Input
- validation
- work with numbers stack to be calculated

Also these is separate Rpn\\Cli class in order to be used as part of CLI Application.

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

[](#installation)

Since this planned to be used via composer please clone this repository and run

```
composer install
```

CLI RPN Calculator - Usage
==========================

[](#cli-rpn-calculator---usage)

In order to use CLI mode please use index.php file. There is a wrapper for some cases as decribed below.

Use cases
---------

[](#use-cases)

1. Using with optional `--expression` parameter. In this case application calculates result and gives it as output. Exit code is 0.

```
php index.php --expression="2 1 12 3 / - +"
```

2. Using as step-by-step calculator. Runs as

```
php index.php
```

And then incrementally giving operands and operators

```
  > 5
  5
  > 8
  8
  > +
  13
  >r
  >2 1 12 3 / - +
  -1
  >
```

Available commands in step-by-step mode
---------------------------------------

[](#available-commands-in-step-by-step-mode)

- q - quits application
- r - resets calculator`s state and could be used in case when you want to reset calculation
- h - prints hint about commands could be used

ToDo
====

[](#todo)

As far as this is quick solution it is not well structured. Hope this will be fixed in future. Items described below need to be added for package to be finished. Obviously need more time to finish that and hope this could be done in future. Or you are welcome to fork and add :)

Exceptions
----------

[](#exceptions)

For now Rpn\\Validator just echoes messages if something is wrong. For sure this is hard-code and needs to be refactored to throw exceptions Possible location of Exceptions classes could be used as src/Exceptions under Rpn\\Exceptions namespace.

Under this item I assume that throw and catch (in client code) needs to be added in order to correct work.

Tests
-----

[](#tests)

This Calculator could be automatically tested by `phpUnit` and btw that was also one of reasons to add composer.json. In future `require-dev` section can be added with phpunit.

Add more operations
-------------------

[](#add-more-operations)

As far as only 4 basic operations are supported it would be great to add more operations, possibly all :)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2300d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f6e5ed1da722746fea0d5cfa7d98174419bfc9ed934dcdcb4e3b59d6f90c840?d=identicon)[misterspelik](/maintainers/misterspelik)

---

Top Contributors

[![misterspelik](https://avatars.githubusercontent.com/u/3395617?v=4)](https://github.com/misterspelik "misterspelik (5 commits)")

---

Tags

clihelpermodulecalculatorRPN

### Embed Badge

![Health badge](/badges/misterspelik-rpn-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/misterspelik-rpn-calculator/health.svg)](https://phpackages.com/packages/misterspelik-rpn-calculator)
```

###  Alternatives

[buggregator/trap

A simple and powerful tool for debugging PHP applications.

2591.7M40](/packages/buggregator-trap)

PHPackages © 2026

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