Skip to content

Instantly share code, notes, and snippets.

import {UnusualSpendingDetector} from "../src/UnusualSpendingDetector";
describe('UnusualSpendingDetector', () => {
const currentMonth = '2020-02';
const previousMonth = '2020-01';
const userId = '1234';
let paymentsRepository;
let detector;
beforeEach(() => {
// From Rachel M. Carmena's https://github.com/rachelcarmena/code-smells
import java.util.Vector; // https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html
public class CoolStack extends Vector {
public void push(Object element) {
insertElementAt(element, 0);
}
// From Rachel M. Carmena's https://github.com/rachelcarmena/code-smells
public class DistanceCalculator {
public double betweenPoints(int x1, int y1, int x2, int y2) {
return Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow(x2 - x1, 2));
}
public double toOriginFrom(int x, int y) {
return Math.sqrt(Math.pow(y, 2) + Math.pow(x, 2));
}
<?php
class Manager {
Worker $worker;
// some functions
public function doThing() : void {
$this->worker->doThing();
}
<?php
// As a direct chain of calls
class FlightBooking {
// ...
public function isSeatAvailable(int $rowNumber, string $seat) : boolean {
return $this->plane->getRow($rowNumber)->isAvailable($seat);
}
}
// Adapted from Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells
<?php
class Address {
private string $addressLine1;
private string $addressLine2;
private string $city;
private string $state;
private string $country;
// Adapted from Rachel M. Carmena's https://github.com/rachelcarmena/code-smells
// see also Ds\Vector in https://www.php.net/manual/en/class.ds-vector.php
<?php
class CoolStack extends Ds\Vector {
public function push(...$values): void {
parent::push(...$values);
}
// Adapted from Rachel M. Carmena's https://github.com/rachelcarmena/code-smells
<?php
class DistanceCalculator {
public function betweenPoints(int $x1, int $y1, int $x2, int $y2) : float {
return sqrt(pow(($y2 - $y1), 2) + pow($x2 - $x1, 2));
}
public function toOriginFrom(int $x, int $y) : float {
// From Fixing Object oriented abusers, Manh Phan https://ducmanhphan.github.io/2020-01-24-Fixing-object-oriented-abusers/
<?php
class CheckoutHandlder {
// ...
public function convertToCurrency(float $price, string $currencyTo) : float {
if ($currencyTo === "EUR") {
return $price * 0.9;